Angular JS: http.post returns null in Internet Explorer

I am making an ajax call from Angular JS:

var response = $http.post( '/services/login/?_nochache='+new Date().getTime(), JSON.stringify(credentials) ); 

I am adding the _nocache parameter, assuming that maybe some kind of cache or something like that.

I also convert the credentials object to a string, thinking that Internet Explorer cannot recognize the object.

I really got lost here. In chrome, the call works fine, in IE 10 the service response is null.

What could be the reason for this?

EDIT

The service returns 401 , which is normal, because the user is mistaken, but the answer should be (as in other browsers), an error line in which the user says that it is wrong, in this case is zero.

I use the promise as follows:

 promise.then(onLoginOk, onLoginError); ... function onLoginError(response) { console.log(JSON.stringify(response)); } 

Console returns

 { "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": "" } 

EDIT

Here is the response body that I get in IE. enter image description here

These are the headers I get with 401 , which is correct, but the response body is erroneous. enter image description here

+8
javascript angularjs internet-explorer ajax
source share
2 answers

This seems like my problem.

In my case, my query function works well in every browser except MS Edge.

I tried to find a solution or a reason, and finally I got one.

Some answers suggest adding tags, e.g.

 <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 to config e.g.

 $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 they could not solve my problem.

Finally, I saw that one answer said that this could happen in the form of policy caching in Edge.

This can happen when I use a local server to send requests or receive responses.

And it will disappear when the test on another server is not local.

I hope your problem is the same as mine.

+1
source

This is a kind of stretch, please don't go crazy if I am wrong here. You have no comments to comment.

Have you looked at this article? Error 401 and 403 only in Internet Explorer (not in Chrome, Firefox, ..) - IIS configuration?

0
source

All Articles