I'm making an ajax call from Angular JS:
var response = $http.post(
'/services/login/?_nochache='+new Date().getTime(),
JSON.stringify(credentials)
);
I'm adding the _nocache
setting, thinking that maybe some cache or something like that.
I'm also converting the object credentials
into string thinking that Internet Explorer could not recognise the object.
I'm really lost here, In chrome the call works perfectly, in IE 10, the response of the service is null.
What can be causing this?
The service is returning 401, which is ok, since the user is wrong, but the response should be (as is in other browsers), the error string saying the user is wrong, in this case is null.
I'm using the promise like this:
promise.then(onLoginOk, onLoginError);
...
function onLoginError(response) {
console.log(JSON.stringify(response));
}
The console returns
{
"data": null,
"status": -1,
"config": {
"method": "POST",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://dev.site.com:8000/api/auth/login/",
"data": {
"username": "[email protected]",
"password": "password"
},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8"
}
},
"statusText": ""
}
Here is the Response body I get in IE.
These are the headers I get with the 401
which is correct, but the response body is wrong.
This seems like same problem of mine.
In my case, my request function works well in every browser except MS Edge.
I tried to find solution or reason, and finally I got one.
Some answers suggested adding tags like
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT" />
or adding code into config
like
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
// extra
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
but these couldn't solve my problem.
Finally I saw one answer said this may occurred by a kind of policy handling caches in Edge.
This can occur when I use local server to send requests or get responses.
And it will gonna disappear when test on other server not on local.
I hope your problem is same as mine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With