Bin*_*min 6 ajax jquery jsonp timeout
jQuery的:如何启用timeout的$.ajax({dataType:'jsonp'...?有什么解决方案吗?http://jsfiddle.net/laukstein/2wcpU/4
$.ajax({
type:"GET",
url:'http://lab.laukstein.com/ajax-seo/.json',
dataType:'jsonp',
timeout:200, // Not working with dataType:'jsonp'
success:function(data){$('#content').html(data.content);},
error:function(request,status,error){$('#content').html('request failed');}
});
Run Code Online (Sandbox Code Playgroud)
我不喜欢使用一些插件,比如http://code.google.com/p/jquery-jsonp.
这是我的解决setTimeout方案clearTimeout http://jsfiddle.net/laukstein/2wcpU/7/
$('#content').ajaxStart(function(){
$(this).html('Loading...');
});
var timer=window.setTimeout(function(){
$('#content').html('Loading seems to be taking a while. Try again.');
},2000);
$.ajax({
type:"GET",
url:'http://lab.laukstein.com/ajax-seo/.json',
dataType:'jsonp',
success:function(data){
window.clearTimeout(timer);
$('#content').html(data.content);
},
error:function(){
window.clearTimeout(timer);
$('#content').html('The request failed. Try to refresh page.');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4476 次 |
| 最近记录: |