jQuery getJSON与超时

问题描述:

在调用yahoo Web服务(http://boss.yahooapis.com/ysearch)以返回数据集时,是否可以设置超时并在例程结束后退出该例程?

When making a call out to the yahoo web service (http://boss.yahooapis.com/ysearch) to return a data set, is it possible to set a timeout and exit the routine once its elapsed?

jQuery.getJSON("http://boss.yahooapis.com/ysearch/...etc",
        function (data) {
              //result set here
            });

您可以使用超时选项

http://api.jquery.com/jQuery.ajax/

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback,
  timeout: 3000 //3 second timeout
});