JQuery Ajax settings : Timeout -


i'm using jquery ajax method call service rest api. have added timeout value of 5 seconds service call.

$.ajax({     timeout:5000,     type:"post",     url:"serviceurl",     data: fooandstuff,     error:function(){},     success:function(data){ console.log(data); }    }); 

this function call. testing when service down , don't think timed out after 5 seconds. because took while , when service returned response.

so, i'm trying understand how jquery implements timeout.

in error callback function try debug if getting timeout this-

error: function(x, t, m) {         if(t==="timeout") {             alert("got timeout");         } else {             alert(t);         }     } 

error event handler takes 3 arguments (xmlhttprequest, textstatus, , message) when timeout happens, status arg 'timeout'

a working timeout demo :

fiddle


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -