我是外部页面内容的AJAXing.大多数情况下,负载不到一秒钟,但有没有一种方法我可以淡入div(假设一个预加载div),如果说负载超过3秒就会出现?所以像这样......
$targetPoint.load($dataImportURL + " " +$rawCollectionPoint,function(){
if (($(this).load >= 3))
{
alert ("Its taken more than 3 seconds to load");
}
});
Run Code Online (Sandbox Code Playgroud)
看一下JavaScript setTimeout函数.
当你发送你的ajax电话时......
var timeout = setTimeout(function(){
alert ("Its taken more than 3 seconds to load");
}, 3000);
Run Code Online (Sandbox Code Playgroud)
当ajax调用完成时取消超时触发器.
clearTimeout(timeout);
Run Code Online (Sandbox Code Playgroud)
编辑:您可能必须使用jQuery中的.ajax()函数,以便您可以利用beforeSend和成功回调
像这样......
var timeout;
$.ajax({
url: $dataImportURL + " " +$rawCollectionPoint
beforeSend: function(){
timeout = setTimeout(function(){
alert ("Its taken more than 3 seconds to load");
}, 3000);
}
success: function(data){
clearTimeout(timeout);
$targetPoint.html(data);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1576 次 |
| 最近记录: |