开发者

Set timeout on jQuery .load

开发者 https://www.devze.com 2022-12-08 06:01 出处:网络
I want to have a timeout after 5开发者_如何学Python seconds and then display \"Unable to fetch page\". But im not sure how to go about it... Heres what I got so far...

I want to have a timeout after 5开发者_如何学Python seconds and then display "Unable to fetch page". But im not sure how to go about it... Heres what I got so far...

$(document).ready(function() {
                    $('#content').html('<br><br><br><br><img src="load.gif" border="0"><br><br><strong>Generating Link...</strong>');
                $("#content").load("ajax.php");
})


var tick = function() {
             $("#content").html('Unable to fetch page!');
           }

$(document).ready(function() {

                var loadTimeout = setTimeout(tick, 5100);

                $.ajax({
                  url: "ajax.php",
                  timeout: 5000,
                  success: function(data) {
                    $("#content").html(data);
                    clearTimeout(loadTimeout);
                  }
                });

})
0

精彩评论

暂无评论...
验证码 换一张
取 消