Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and Javascript!

Status
Not open for further replies.

lutherbach

Programmer
Oct 24, 2001
3
BR
Is it possible to call a php file using a javascript?
Something like the php function include().
 
Javascript can't do anything with a PHP file differently from what it can do with any other file. I keep on seeing these questions being asked. Remember, browser Javascript is client-side, while PHP is server-side.

Javascript can call an external file, as in
<script language=&quot;Javascript&quot; src=&quot;myfile.js&quot;>
</script>

Well, there is no reason that this .js file can't have another extension, such as .php. However, the output of that PHP file has to be valid Javascript, or it will be meaningless.

In other words, there is no direct way to get an include() function in browser script, such as Javascript or HTML. However, if you call an external script file as mentioned above, that file can run Javacript document.write() statements, which can write HTML into the document. This can be placed anywhere in your HTML file, so it can have the same effect as an include, as long as the browser supports Javascript.

But remember this: as far as the browser is concerned, there is nothing magical about PHP. The browser just sees iteslf getting text from the server, and for the browser to make sense of that text, it has to take the form of either HTML or Javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top