工作我使用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