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.
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.
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* '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With