简体   繁体   English

如果花费太多时间,则带有错误消息的jQuery加载函数

[英]Jquery Load Function with Error Message if taking too much time

Is there any way to handle the loading time, I mean when jquery load function taking too much time I want to show a error message. 有什么方法可以处理加载时间,我的意思是当jquery加载函数花费太多时间时,我想显示一条错误消息。 Following code is working perfectly. 以下代码运行正常。

var href=$(this).attr('href');
$('#load').load(href);

Please Help me ! 请帮我 ! Thanks . 谢谢 。

Please try this, and read Jquery ajax documentation 请尝试此操作,并阅读Jquery ajax文档


var href=$(this).attr('href');
$.ajax({
    url: href,
    error: function(){
        // will fire when timeout is reached
    },
    success: function(){
        //do something
    },
    timeout: 3000 // sets timeout to 3 seconds
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM