0

In my webapp I have opened a modal and in that modal I'm processing some data using with ajax in another page(ajax.php), after the processing is done in the ajax.php I do:

header("location: blah.php");

But since I'm in another page and the whole process is going on with ajax request the page doesn't do anything, when I check the ajax request via FireBug, I see the request goes red with this error:

302 Moved Temporarily error

How can I redirect in this scenario?

Thanks in advance

behz4d
  • 1,819
  • 5
  • 35
  • 59
  • @h2ooooooo it has nothing to do with that, I need it to be in PHP since I want to make the redirection in ajax.php – behz4d Dec 02 '13 at 10:47
  • Then read the headers from the ajax call. Read the documentation on [`$.ajax`](http://api.jquery.com/jQuery.ajax/). We're not going to make all the code for you, when you haven't tried yourself. [Here's another question you might want to read](http://stackoverflow.com/questions/1557602/jquery-and-ajax-response-header). All you want to do has already been done a million times, it's just for you to put the puzzle pieces together. – h2ooooooo Dec 02 '13 at 10:50
  • 2
    There's no reason to be rude. You can't do it from PHP unless you read the response HTTP headers, in which my response mentioned how to read these. Read your HTTP logs, and don't expect to get responses when you don't bother to do anything yourself, and when you then *do* get responses, consider being polite. – h2ooooooo Dec 02 '13 at 11:14

1 Answers1

1

The response already redirects the AJAX request. It does not change the page the user is currently seeing in the browser. That's the way it is and you cannot change it from within PHP. The AJAX request was executed entirely in the background, that's the point of AJAX. Whatever response the server returns does not directly visibly affect anything on the site that's currently visible to the user. You have to handle the response entirely in Javascript.

If you want to redirect the user to another page based on a failed AJAX response, you'll have to do so in Javascript:

$.ajax(..., function (data) {
    if (/* something or other */) {
        window.location = /* other page */;
    }
});
deceze
  • 510,633
  • 85
  • 743
  • 889