Page 1 of 1

Including a JS file into a PHP file and passing values back

Posted: Thu Oct 25, 2007 11:34 am
by impulse()
Hi.

I have a PHP page which uses Ajax to fetch MySQL database results. The Ajax function is included in the head as a .js file and the PHP code to query the database is included in the head, also as a Javascript file, but the extension is .PHP

Code: Select all

<script language="javascript" type="text/javascript" src="./js/search_suggestions.php"></script>
But I want to be able to pass a GET variable from the PHP that is loaded in the browser back to the search_suggestions.php page so the database querying can be more dynamic.

How could this be done? I've played about but the search_suggestions.php page doesn't read the GET variables from the page loaded by the browser.

Posted: Thu Oct 25, 2007 11:48 am
by Christopher
Typically, you include a PHP script that uses JSON to initialize/communicate to the Javascript, then the Javascript sets up communication back to PHP with Ajax. You can also have PHP push JSON back to the browser. There are a number of libraries that can help you with this.