Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting timeout on jQuery's get shorthand

Is it possible to set the ajax timeout parameter using jQuery's get shorthand? If not, do requests sent with the shorthand ever timeout?

jQuery.get(
    url, 
    [ data ], 
    [ callback(data, textStatus, XMLHttpRequest) ], 
    [ dataType ] 
)

Thanks.

like image 894
Travis Avatar asked Jul 07 '10 07:07

Travis


1 Answers

Is it possible to set the ajax timeout parameter using jQuery's get shorthand?

No, not per request, though you can use $.ajaxSetup() to do it for all requests.

If not, do requests sent with the shorthand ever timeout?

No, by default they won't (unless you used $.ajaxSetup({ timeout: value });), the default timeout option isn't defined, the same as 0 meaning "don't timeout".


To do a timeout per request and not globally, you'd have to switch to the longhand format:

$.ajax({
  url: url,
  data: data,
  success: callback(data, textStatus, XMLHttpRequest),
  dataType: dataType,
  timeout: timeoutvalue
});
like image 178
Nick Craver Avatar answered Oct 19 '22 10:10

Nick Craver