Re: php/ajax question



At 1:30 AM +0500 12/31/06, Fahad Pervaiz wrote:
When you use "HEADER()", an HTTP header is sent to client browser. So when using with an ajax call the header cannot redirect the page. For the purpose you have to use include or require. If you want to redirect client browser to some other location then you can work around with javascripts.

But when using ajax. headers cannot redirect client browser window.


Arrggg -- that's what I was afraid of. I'll have to direct my attention to javascript.

Thanks.

tedd

---


Let me know if u need any more help

--- ORIGINAL ---
Hi gang:

I have a small php script that behaves differently depending upon
who's calling it. The code is:

<?php session_start(); /* a.php */
ob_start();
$_SESSION['var'] = "test";
ob_clean();
header("Location: <http://www.example.com/b.php>http://www.example.com/b.php";); /* Redirect browser */
exit; ?>

If the code is called directly, namely <http://www.example.com/a.php,> http://www.example.com/a.php,
then the $_SESSION var is filled with "text" and the redirect is
realized.

However, if the php script is called via ajax:

-snip- preceding ajax

function sndReq(action)
{
http.open('get', 'a.php');
http.send(null);
}

Then the $_SESSION var is filled with "test", but the redirect is not realized.

Why can't the php script redirect the browser when called via ajax ?

Thanks.

tedd


--
Regards
Fahad Pervaiz
<http://www.ecommerce-xperts.com>www.ecommerce-xperts.com


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
.



Relevant Pages

  • Re: AJAX Page Loading Failure on Some Browsers
    ... the updateprogress control is designed to run during an async postback. ... the ajax code receives this, and sets the document.location to the new url (to do the redirect). ... if you are doing this on your local box, the redirect response may come before the progress bar even has chance to start. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: php/ajax question
    ... When you use "HEADER()", an HTTP header is sent to client browser. ... using with an ajax call the header cannot redirect the page. ... But when using ajax. ...
    (php.general)
  • Re: Web Page Question
    ... Search google on asp.net ajax atlas for dozens of samples. ... On submit the page the info is saved to a db, connects to third party web apps and retrieves data, and third party data is saved. ... I want to be able on submit is redirect the user to a loading page while the app is doing the above functionality and then when finished user is redirect to a new page. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Redirect during Async Postback causing an error
    ... generally you can not do a response redirect from an async postback. ... I have three update panels and a couple of AJAX toolkit extenders on ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: sessions and redirecting in opera
    ... All the more reason why a header redirect should be ... Opera get's the redirect, but still has the page with the same ... exit(); // exit doesn't really make a difference for Opera ...
    (comp.lang.php)