plodos Posted April 4, 2008 Share Posted April 4, 2008 I can call other php pages inside of the php pages like index.php <?php include(header.php); include(frontPage.php); include(footer.html); ?> but how can I call, for example .inc .html pages inside of the HTML pages ? Who knows the javascript code ? index.html Javascipt(footer.inc) Javascript(header.html) Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/ Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 Why not just include them with PHP? As far as i'm aware, all you can do with javascript is include other javascript files. Of course, those javascript files could contain text to be written to the screen, but it's probably going to get messy. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509050 Share on other sites More sharing options...
lordfrikk Posted April 4, 2008 Share Posted April 4, 2008 You can include files via AJAX (which is Javascript). Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509096 Share on other sites More sharing options...
patrick24601 Posted April 4, 2008 Share Posted April 4, 2008 I think what we might have here also is a slight misunderstanding of what runs where. One of the main reasons you cannot do what you are saying is that it is not physically possible. The two files you want to include reside on the server. Javascript (a client side language) will have no clue about them. Only server side languages like PHP, ASP, etc. would be able to read them from the server and interpret them. Likewise server side programming languages cannot be used to get/write files on the client side. Now I am sure there are workarounds because we have this lovely conduit called a web browser which will let the client and server side talk to each other. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509156 Share on other sites More sharing options...
Yesideez Posted April 4, 2008 Share Posted April 4, 2008 AJAX is a step in the right direction but having never used it I've no idea to what extent this can be used to solve the problem in hand although patrick is spot-on regarding server and client side. If all you're needing is to include some JS functions then why not include them anyway? If they're not being called they won't be used. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509159 Share on other sites More sharing options...
haku Posted April 4, 2008 Share Posted April 4, 2008 Patrick is not spot on at all, other than the fact that javascript is clientside and php is serverside. Its entirely possible to use Javascript to interact with files on the server and include them onto a page. Its called AJAX (and SJAX as well), and there are thousands of web pages that. I use it regularly myself. You use javascript to create an HTTPRequestObject that then calls server side scripts, then takes the information received from the scripts and inserts it in the page. BUT using AJAX for includes is both inefficient and unreliable, as the user may have javascript turned off, and because javascript is dependent on browser versions. Includes should be included serverside. However, html pages cannot have includes - for the most part. If the programmer sets up their server to be able to parse PHP files with a .html extension it can be done, or if they use a mod re-write to make a .php file appear as having a .html extension, it can be done. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509265 Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 Personally, i agree more with Patrick. Whilst it is true that you can use AJAX, at the end of the day it is still the server side language which is doing the work. All you are doing is making an asynchronous request (i.e. without the whole page reloading) to the server - the javascript it just loading that content, whatever it may be. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509284 Share on other sites More sharing options...
haku Posted April 4, 2008 Share Posted April 4, 2008 That's not necessarily true at all. You don't even need a script on the server side - if they are html files, you can access them directly with your ajax function, and include the results on your page as is. The javascript calls the pages and loads them. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509287 Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 Yes that's true - but you are still making a request to the server. In my view, the including of files is therefore a server side operation. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509288 Share on other sites More sharing options...
haku Posted April 4, 2008 Share Posted April 4, 2008 Lets review what Patrick said: The two files you want to include reside on the server. Javascript (a client side language) will have no clue about them. Javascript does have a clue, or it wouldn't be able to read them. Only server side languages like PHP, ASP, etc. would be able to read them from the server and interpret them. Yet Javascript can both read and interpret the files. Now lets look at what you have said: it is still the server side language which is doing the work Javascript is not a server side language. And it is doing all the work in a situation where it is accessing .html files. There isn't even a server-side language in play in such a situation. you are still making a request to the server. In my view, the including of files is therefore a server side operation. Except that its happening on the client side. Which makes it a client side operation. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509292 Share on other sites More sharing options...
maexus Posted April 4, 2008 Share Posted April 4, 2008 AJAX does use Javascript but I thought AJAX was only a method for Javascript to pass data and functionality off to a server side script to do the heavy lifting. Like a AJAX script for a voting system. Javascript isn't actually doing anything other than taking the user input and passing it to a server side script. The SSS is the one who does all the backend work. If you use AJAX to request to include a file, why not just use the SSS directly and cut out the middle man (Javascript). Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509384 Share on other sites More sharing options...
drewbee Posted April 4, 2008 Share Posted April 4, 2008 Javascript cannot interpret PHP code. That is a ludicris statement. Yes, javascript can pass information to the PHP script. The PHP can output code that javascript can understand, but to say javascript can interpret PHP is a little on the wild side. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509418 Share on other sites More sharing options...
maexus Posted April 4, 2008 Share Posted April 4, 2008 Javascript doesn't handle PHP directly or... at all. Javascript passes data/requests to the server, which then passes it to the server side script to do the heavy lifting. The server side script then returns a results, usually XML (The X in AJAX) which is read by Javascript. All of this happens asynchronously. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509494 Share on other sites More sharing options...
haku Posted April 5, 2008 Share Posted April 5, 2008 You guys are hung up on the AJAX script requiring a server-side script. AJAX can access an html file that is not a script at all, and insert the results into the page it is running on, which would do what the OP was looking to do. I do it with XML pages all the time - they aren't scripts, they are hard coded pages. In such a case, javascript is interacting directly with the server, retrieving a file and using the results of that file on the page the javascript is run on. No server-side scripts at all. Javascript cannot interpret PHP code. I agree. It can only process the results that the PHP code sends back to it. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509746 Share on other sites More sharing options...
Psycho Posted April 5, 2008 Share Posted April 5, 2008 Just because I want to throw fuel on the fire... You are all wrong when you say that javaScript is only run client-side. JavaScript can be run server-side. So there! http://en.wikipedia.org/wiki/Server-side_JavaScript http://www.amazon.com/Server-Side-JavaScript-Developing-Integrated-Applications/dp/020143329X http://docs.huihoo.com/javascript/ServerJSv14/docs/contents.htm Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509750 Share on other sites More sharing options...
tomfmason Posted April 5, 2008 Share Posted April 5, 2008 JavaScript can be run server-side. So there! yes it can and I would recommend mozilla rhino for anyone that is interested in playing around with it. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509754 Share on other sites More sharing options...
haku Posted April 5, 2008 Share Posted April 5, 2008 You are all wrong when you say that javaScript is only run client-side. JavaScript can be run server-side. No kidding! I honestly had no idea. That's pretty cool, although kind of off-topic to the current discussion. But cool nonetheless! Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509775 Share on other sites More sharing options...
maexus Posted April 5, 2008 Share Posted April 5, 2008 My ultimate point was to use PHP (shocking I would suggest this on a PHP forum) the include/require functions work perfect for this. Also, I don't feel Javascript should be used for something like this. It's relying on the browser's javascript to make this work so that is horrible for usability. What happens when Javascript is turned off or blocked by the browser? If someone can point out why JS is better in this situation, by all means, speak up. To me, it seems like using a wrench to drive in a nail. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-510012 Share on other sites More sharing options...
patrick24601 Posted April 5, 2008 Share Posted April 5, 2008 Wow. You guys really jumped on that poor Patrick guy! Let's review what I think he was trying to say: Javascipt(footer.inc) Javascript(header.html) Will not work. Javascript cannot access those files because they on the server. You have to have javascript call a web page/code of some sort via http to get data back. Whether it is HTML/PHP does not matter. It is on server. Javascript does not know about it. Therefore Javascript must call it from the server like everybody else. Quote Link to comment https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-510159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.