我有一個簡單的PHP頁面(用於測試),簡單地調用header("Location: http://www.example.com ");exit;
,駐留在同一臺服務器上,在同一個目錄中有以下的jQuery的Javascript另一個文件:jQuery AJAX不重定向?
$(document).ready(function() {
jQuery.ajax({
type : 'GET',
url : 'bounce.php',
error : function(xhr, status, error) {
console.log("ERROR: ", xhr, xhr.status, xhr.getAllResponseHeaders());
},
complete : function(xhr, status) {
// Get headers of the response
console.log("COMPLETE: ", xhr, xhr.status, xhr.getAllResponseHeaders());
}
});
});
我期待(從幾個其他StackOverflow響應)爲xhr.status
返回「302」,但AJAX調用正在觸發「錯誤」事件(然後是「完成」事件),並且xhr.status
正在返回0
(零),並且.getAllResponseHeaders()
正在返回null
(在錯誤和完整功能中)。
Firebug顯示「302 Moved Temporarily」和響應標題。 那麼爲什麼會觸發錯誤事件,而不是傳遞正確的302代碼和標題?這是因爲彈跳腳本和抓取腳本都在同一個服務器上,所以它與同源相關嗎?這是jQuery或Javascript的錯?
正確,但我希望javascript至少能夠找出頁面試圖重定向到的位置。但是,現在,getReponseHeaders沒有返回任何內容,所以我無法獲取該「位置」標題。 – MidnightLightning 2011-01-13 21:23:46