在jQuery上设置超时得到速记

Tra*_*vis 13 javascript ajax jquery timeout

是否可以使用jQuery的get速记设置ajax timeout参数?如果没有,用速记发送的请求是否会超时?

jQuery.get(
    url, 
    [ data ], 
    [ callback(data, textStatus, XMLHttpRequest) ], 
    [ dataType ] 
)
Run Code Online (Sandbox Code Playgroud)

谢谢.

Nic*_*ver 17

是否可以使用jQuery的get速记设置ajax timeout参数?

不,不是每个请求,尽管您可以使用$.ajaxSetup()它来执行所有请求.

如果没有,用速记发送的请求是否会超时?

不,默认情况下它们不会(除非你使用$.ajaxSetup({ timeout: value });),默认timeout选项没有定义,0意思是"不要超时".


要按请求执行超时而不是全局超时,您必须切换到手写格式:

$.ajax({
  url: url,
  data: data,
  success: callback(data, textStatus, XMLHttpRequest),
  dataType: dataType,
  timeout: timeoutvalue
});
Run Code Online (Sandbox Code Playgroud)