Page 1 of 1
PHP and AJAX problem
Posted: Fri Mar 23, 2007 3:20 am
by yadafarin
hi
I have problem with AJAX and php.
In .htm file: I load content of a .php file into my layer (<div ...).
the major my script of .php file is:
header("Locatoion: /search.php");
i want .htm file is redirect to /search.php .
But /search.php is load into layer and .htm doesn't redirect.
Can u help me.
thanks
Posted: Fri Mar 23, 2007 3:25 am
by Kieran Huggins
you want to load some ajax content that can reload the whole page with a different URL?
Posted: Fri Mar 23, 2007 7:25 am
by aaronhall
When you load a PHP script via XMLHttpRequest, it's a separate request from that of the page making the AJAX request. You'll need to handle the redirect with Javascript using
Code: Select all
location.href="http://mysite.com/page.htm";
RE: aaronhall
Posted: Fri Mar 23, 2007 10:42 am
by yadafarin
thank u Kieran Huggins but aaronhall:
I added this line to .php file:
Code: Select all
echo '<script language="javascript">location.href="/search.php";</script>';
This script load in my layer (<div ...) but .htm file should be refresh to run this script.
Can I use a method to running this script when .php is load?
Posted: Fri Mar 23, 2007 10:47 am
by Kieran Huggins
This won't always work as you expect.
I strongly encourage you to use jQuery and the $.getScript("test.js"); method
Posted: Sat Mar 24, 2007 5:38 am
by aaronhall
Again, the redirect needs to be handled from the script calling the AJAX script, not from the script being called. The location.href expression can be placed somewhere after the javascript function making the AJAX request, preferably in the call's "onSuccess" event handler.