我正在使用下面的代码片段从某个webAPI获取数据。
data.responseText在FireFox中运行良好,但在IE L中未定义
我也尝试过使用data.responseJSON,但它在IE中不起作用。
请给我这个问题的解决方案。
这是我正在使用的代码。
$.ajax({
type: "GET",
url: serviceUrl,
contentType: "application/json",
data: "{'slid':'" + slidname + "'}",
async: false,
crossDomain: true,
complete: function (data) {
alert("hii");
alert(data.responseText);
}
});发布于 2015-03-17 23:47:09
IE的哪个版本?如果是IE9或更低版本,问题可能出在您的jQuery版本上-请参阅http://jquery.com/browser-support/。
否则,您可以尝试让浏览器对ajax请求数据进行格式化是否有帮助:
$.ajax({ type: "GET", url: serviceUrl, contentType: "application/json", data:JSON.stringify( {"slid": slidname} ), async: false, crossDomain: true, complete: function (data) { alert("hii"); alert(data.responseText); } });
如果同样失败,您可能希望尝试将"jsonp“作为ajax调用的dataType,因为您有一个跨域请求。
$.ajax({ type: "GET", url: serviceUrl, contentType: "application/json", data: JSON.stringify( {"slid": slidname} ), async: false, crossDomain: true, dataType: "jsonp", complete: function (data) { alert("hii"); alert(data.responseText); } });
https://stackoverflow.com/questions/29103076
复制相似问题