-1

Trying to call one service from angular using $http. Normally the service will return 200 status code. But if the session is our it will return status 302. This I can see in the developer console network tab also. But in code the status code coming as -1

Here is the code

function getData(reqUrl) {
                return $http({
                    method: 'GET',
                    url: reqUrl
                });
            }


function get******(serviceName, callback) {
                getData(DataClient.serverUrl + '/****/services/rest/Q******/*****/' + serviceName)
                    .then(function (res) {
                        if (res.status == -1) {// here we need to check with 302
                            //session out
                        } else {
                           // rest of the code
                        }

What could be the issue? Why angular is giving -1 instead of 302?

Jota.Toledo
  • 27,293
  • 11
  • 59
  • 73
Anoop LL
  • 1,548
  • 2
  • 21
  • 32

1 Answers1

0

redirection on 302 Found is done by browser.

So in the handler you will always get response from location you've been redirected to.

Check Prevent redirection of Xmlhttprequest and AngularJS docs on $http, also spec for XMLHttpRequest still does not allow handle redirection by client code.

skyboyer
  • 22,209
  • 7
  • 57
  • 64