1

I have a stored procedure which takes 10 sec to execute and returns 10,000 records of data. But every time I call the API, the call results in a connection timeout. If I am able to increase the timeout of the REST request then it would be working fine.

My main question is: If a timeout occurs, how do I get the timeout error in the AJAX request, so that I show the user that timeout occurred? Every time the AJAX call fails and I do not receive an error indicating a timeout happened or that the data was not found.

mbuechmann
  • 5,413
  • 5
  • 27
  • 40
MumbaiKandivali
  • 121
  • 1
  • 1
  • 9

2 Answers2

4

Here is the thing you can implement to detect timeout error and show on front page for user:

$.ajax({
    url: "/ajax_json_echo/",
    type: "GET",
    dataType: "json",
    timeout: 1000,
    success: function(response) { alert(response); },
    error: function(xmlhttprequest, textstatus, message) {
        if(textstatus==="timeout") {
            alert("got timeout");
        } else {
            alert(textstatus);
        }
    }
});​
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33
  • I Tried but in ajax fail i would get response Text like that. How i get "developerMessage" form $.parseJSON(xhr.responseText); Then i will validate with that mesasge. "{"errorCode":500,"message":"We had an error.","developerMessage":"Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.","moreInfo":"http://supershuttle.com"}" – MumbaiKandivali Oct 18 '18 at 08:44
  • humm so you managed to get what you wanted. Can you accept my answer if it was the most helpful? – Himanshu Upadhyay Oct 18 '18 at 09:57
  • Its working now. Thanks – MumbaiKandivali Oct 18 '18 at 11:16
  • @MumbaiKandivali, Can you accept my answer if it was the most helpful? – Himanshu Upadhyay Oct 18 '18 at 11:28
1

I think if you are working with rest api and specially if you are as a client,it is always better to keep time-out.I have observed the similar issue of connection time-out and the problem was solved by putting the piece of code connection.setConnectTimeout(5000); will timeout in 5 sec.