工作我使用XMLHttpRequest對象爲我的AJAX調用已被罰款跨瀏覽器與我創建基於請求類型和參數等的XMLHttpRequest只能在IE
但我返回JSON回調處理程序工作我現在整合外部的RESTful API返回一個JSON字符串,由於某種原因它只能在IE(以IE 8測試)爲我工作。使用fiddler 2我已經確定API正在返回正確的數據。
我得到的4 XMLHttpRequest.readyState但XMLHttpRequest.status僅適用於Chrome,Safari和FF返回0。我讀了使用本地服務器(測試服務器)有時當你總是得到零狀態,所以我繞過我的狀態檢查,但仍然得到了XMLHttpRequest.responseText一個空字符串。
function ajaxRequest(requestType,url) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
switch (requestType)
{
case 5:
//Home postcode search
showAddresses("home", xmlhttp.responseText);
break;
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
您的AJAX調用託管的腳本在哪裏?您要請求的URL是什麼? – robertc 2012-02-27 13:01:11