【发布时间】:2015-10-20 08:45:41
【问题描述】:
我正在尝试进行 ajax 调用,将 async 属性设置为 false,但它在 chrome 和 ie 上工作时出错。
我知道由于用户体验问题,Firefox 强烈推荐异步 ajax 调用,但我需要在继续做其他事情之前获得响应,并且可以(并且强制)等待直到收到响应..
这是工作和不工作的代码,任何帮助将不胜感激。
data = $.ajax({
url: Common.serverPath + 'recovery/list',
crossDomain: true,
dataType: 'json',
async: true,
type: 'GET',
contentType: 'application/json',
xhrFields: {
withCredentials: true
}
});
setTimeout(function(){ console.log(data.statusText);
},3000);
控制台:确定
data = $.ajax({
url: Common.serverPath + 'recovery/list',
crossDomain: true,
dataType: 'json',
async: false,
type: 'GET',
contentType: 'application/json',
xhrFields: {
withCredentials: true
}
});
setTimeout(function(){ console.log(data.statusText); },
3000);
console:InvalidAccessError: 底层对象不支持参数或操作
chrome 和 ie 在两者中都可以正常工作
【问题讨论】:
标签: javascript ajax firefox asynchronous