【发布时间】:2016-08-15 22:07:40
【问题描述】:
我正在从 Angular JS 进行 ajax 调用:
var response = $http.post(
'/services/login/?_nochache='+new Date().getTime(),
JSON.stringify(credentials)
);
我正在添加 _nocache 设置,认为可能是一些缓存或类似的东西。
我还将对象 credentials 转换为字符串,认为 Internet Explorer 无法识别该对象。
我真的迷路了,在 chrome 中调用完美,在 IE 10 中,服务的响应为空。
这是什么原因造成的?
编辑
服务是返回401,没关系,因为用户错误,但是响应应该是(就像在其他浏览器中一样),表示用户错误的错误字符串,在这个案例为空。
我正在使用这样的承诺:
promise.then(onLoginOk, onLoginError);
...
function onLoginError(response) {
console.log(JSON.stringify(response));
}
控制台返回
{
"data": null,
"status": -1,
"config": {
"method": "POST",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://dev.site.com:8000/api/auth/login/",
"data": {
"username": "mail@domain.com",
"password": "password"
},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8"
}
},
"statusText": ""
}
编辑
【问题讨论】:
-
你是如何使用承诺响应的?请张贴代码。
-
使用
IE10时是否到达后端服务(services/login)? -
我猜如果没有到达后端我不会有 401 对吧?
-
你试过 $httpParamSerializerJQLike 吗?有几天我遇到了类似的问题,docs.angularjs.org/api/ng/service/$httpParamSerializerJQLike
-
我有同样的错误:/
标签: javascript angularjs ajax internet-explorer