0

I am trying to handle following scenario using jquery ajax

we have a webservice that usually gets down for maintenance so when we make a call to webservice we want to show specific message i.e. "Service is down for under maintenance". Now to handle that we have written following code

$.ajax({
                 url: objWSConfiguration.VERIFY_USER,
                 dataType: "json",
                 data: jsonData,
                 type: "POST",
                 contentType: "application/json; charset=utf-8",
                 async: false,
                 timeout: 1000,
                 statusCode: {
                    503: function() {

                         navigator.notification.alert(GENERAL_SERVER_DOWN_ERROR_MSG, null, "Hitachi", "OK");

                    }
                 },
                 success: function (responseData, textStatus, jqXHR)
                 {
                    // perform a success processing
                    console.log("WSVerifyUser :response data " + JSON.stringify(responseData));
                    //Check Response Status
                    if(textStatus == "success")
                    {
                        if(responseData.status == STATUS_OK){

                            callback(responseData);

                        }else  if(responseData.status == STATUS_ERROR){

                            callback(responseData.errorMessage);

                        }

                    } else {
                        navigator.notification.alert("Connection Error, Please try again later", null, "Hitachi", "OK");
                    }                      
                 },
                 error: function (jqXHR, textStatus, errorThrown) 
                 {

                     console.log("Error 1 "+textStatus);
                     console.log("Error 2 "+errorThrown);
                     console.log(jqXHR.status);

                    if(textStatus === "timeout") {

                        console.log("Fall here timeout ");

                        //do something on timeout
                        navigator.notification.alert("Request Timed out...",  null, "","OK");
                    } else {
                        // show error to the user about the failure to invoke the service
                       console.log("Fall here no where");
                        navigator.notification.alert(CONNECTION_ERROR_MSG,  null,"", "OK");
                    }
                 }            
             });

we have tried to handle it by adding callback for status code 503 but the problem is it never gets called when our service is down.

it always fall under console.log("Fall here no where"); and textStatus is not returning timeout too in error function

but timeout and service not available are two different things so how can i handle it using ajax

Hunt
  • 8,215
  • 28
  • 116
  • 256

0 Answers0