Status code function not execute on request on phone


#1

Hello!
I’m make request to server by following code:


app.request({ url: urlVar,
                statusCode: {
                    500: function (xhr) {
                        console.log('Error status: 500  Response: ' + xhr.response + '  ResponseText: ' + xhr.responseText + '  StatusText:' + xhr.statusText);
                    },
                    200: function (xhr) {
                        console.log('Status: 200  Response: ' + xhr.response + '  ResponseText: ' + xhr.responseText + '  StatusText:' + xhr.statusText);
                    },
               },
               success: function (data) {
                    console.log(data);
                },
               error: function (xhr, status) {
                    console.log('Status = ' + status);
               }
          });

It works correctly on browser. But the mobile phone does not start the function for error codes when the server is stopped. In the example, only the function for code 500 is present. But in the real code all error codes are listed. But the error function is called, though there the status of the error code is = 0.


#2

Use complete and error callbacks instead of status code callbacks and check statuses there. Also, in cordova environment 0 is also can be a success code