Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP AJAX 12017 Error when calling Header(Location:) [duplicate]

Tags:

I have a jquery function that calls a PHP file via AJAX. Inside that PHP file I have

 header('Location: http://www.google.com');

However this doesn't work, the page is not redirected and the jQuery AJAX call returns an error, no 12017, I can't find much information about this error number.

I have output buffering enabled and have tried placing the header call right at the top of my PHP file but still have no luck. Any ideas? Thanks.

like image 989
David Healey Avatar asked Feb 17 '13 00:02

David Healey


People also ask

What is header in Ajax?

The headers are additional key-value pairs send along with ajax request using the XMLHttpRequest object. An asynchronous HTTP request to the server by using The ajax() function and by including the header it describes to the server what kind of response it accept.


1 Answers

I believe if you are using ajax request, you have to handle redirects within javascript (where the request is made).

If your php script sets the Location header of the response when you make an ajax request, it will try to redirect the ajax request not the page that is displayed in the browser.

You can try to handle the error where you make the request (I would have been more specific if I saw the code making the request).

You can try changing your script so that it returns some kind of status code and then handle this status with js/jquery and make the redirect there:

document.location=' *new url to redirect the browser to* '
like image 190
bssstudio Avatar answered Sep 22 '22 17:09

bssstudio