harshpandya Posted February 11, 2009 Share Posted February 11, 2009 Hi all, If i call javascript function of the PHP file before including that PHP file. Would it cause any problem. I am not sure if that causes the problem. I thought PHP code runs first and it only runs once. so please let me know, if that would cause problem...Thanks, Link to comment Share on other sites More sharing options...
boen_robot Posted February 11, 2009 Share Posted February 11, 2009 PHP runs first, and it's output runs at the browser. That's that.You can safely do <script type="text/javascript">//do something</script><?phpinclude 'something.php';?> in which case the server will first process "something.php", and finally the browser is going to receive the script, along with the output of "something.php". For example, if "something.php" contained <?phpecho 'SOMETHING';?> then the final output would be <script type="text/javascript">//do something</script>SOMETHING and THAT is what the browser will see.To answer your question - no, it won't cause any problems, as PHP and JavaScript have nothing to do with each other. Link to comment Share on other sites More sharing options...
harshpandya Posted February 11, 2009 Author Share Posted February 11, 2009 But what if i am calling the javascript function of the something.php file, will it still be fine. Link to comment Share on other sites More sharing options...
jeffman Posted February 11, 2009 Share Posted February 11, 2009 It has nothing to do with PHP. When it gets to the browser, the PHP output is part of the document, just as if you had hard-coded it there. So if the scripts and functions are arranged in a way that calling them works, it works. If not, not. Same rules as a normal HTML file.What you're saying is the function call is printed above the included material. If it's called from the global space of a script (I mean, not in a function, so the call happens while the script loads), that will be a problem, because the included material hasn't arrived yet--not because it's included, but because it's below. If it's called from a function, like in response to a user action, then that would be after page load, and it should be fine.Did you try it? Are you having a problem? Just trying it should answer your question. If your Firefox error console says that the function doesn't exist, then it's probably the problem I mentioned. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.