How to response status code to client?


My server code is using PHP.

I want to response status 401 code to client:


client code is:

$, {data:data}).then(function (result){
}, function(error){

but I get this error at client:

XMLHttpRequest cannot load Invalid HTTP status code 401
Object {data: null, status: 0, headers: function, config: Object, statusText: ""}

You can see the error status is 0 not 401. So I can’t use ‘interceptors’ catch this error status code.
How to make the error status code is correct response from the server with php?

I found GET method can get right status code.but POST will not.

Object {data: "", status: 401, headers: function, config: Object, statusText: "Authorization Required"}


I’m assuming this is happening when you are running in an emulator or device?

If i’m right i think the problem might be solved if you install the cordova whitelist plugin:


Thanks jawache, but I have the cordova whitelist plugin. These is it after start a project.


Is this in the browser? Or when running on an emulator/device?


i used chrome browser. GET($http.get) method can got correct status code. POST($ method can’t get it.


Ok if it’s just POST and not GET and it’s in the browser, that strongly hints to me that this is a CORS security issue. Does it work as you suspect when you run it on a device?


I am not sure how about on a device. I have changed my solution.
I give up response http status code instead of my own error code.
Server will response the json. {‘ret’:1, ‘errcode’: 101}