21

我有一个通过 AJAX 调用 PHP 文件的 jquery 函数。在我有的那个 PHP 文件里面

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

但是这不起作用,页面没有重定向,jQuery AJAX 调用返回错误,没有 12017,我找不到关于这个错误号的太多信息。

我启用了输出缓冲,并尝试将标头调用放在我的 PHP 文件的顶部,但仍然没有运气。有任何想法吗?谢谢。

4

1 回答 1

9

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* '
于 2013-02-17T00:57:45.773 回答