Jump to content

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509156
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509159
Share on other sites

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.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509265
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509284
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509292
Share on other sites

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).

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509384
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509494
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509746
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-509750
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-510012
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99497-php-vs-javascript/#findComment-510159
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.