This question already has an answer here:
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
</div>
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 */;
}
});