Set timeout on jQuery.load

I want to have a timeout after 5 seconds, and then display "Unable to get page." But I'm not sure how to do this ... That's what I still have ...

$(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"); }) 
+4
source share
1 answer
 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); } }); }) 
+7
source

All Articles