9

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?

EDIT

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

EDIT

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

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

20
  • 1
    how are you using the promise response? please post code. Commented Aug 15, 2016 at 22:25
  • Did it reach the backend service (services/login) when you use IE10? Commented Aug 16, 2016 at 5:18
  • I guess if didn't reach the backend I wouldn't have a 401 right? Commented Aug 19, 2016 at 21:01
  • Have you tried with $httpParamSerializerJQLike ? I had a similar issue some days, docs.angularjs.org/api/ng/service/$httpParamSerializerJQLike Commented Aug 19, 2016 at 21:53
  • I have the same error :/ Commented Aug 19, 2016 at 22:05

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

This is kind of stretch, please don't go nuts if I am wrong here. Don't have the rep points to comment.

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

1 Comment

It looks like you are having an authorization issue and IE is the target of the authorization blocker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.