nowayyy
nowayyy

Reputation: 917

Check if file has been loaded using .load()

How would I check if file has been loaded in a div, and if not, try again (reload it)

I'm using .load() and fancybox to load the file in.

  $('a.button-1').click(function(){

       $('#data').load('form1.html');

});

 $('a.button-2').click(function(){

       $('#data').load('form2.html');

});   

Upvotes: 1

Views: 1720

Answers (1)

James Montagne
James Montagne

Reputation: 78630

You can do something like what is in the jquery docs for load:

$("div").load("/test.html", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $(this).html(msg + xhr.status + " " + xhr.statusText);
  }
});

http://jsfiddle.net/fqMWL/

Although I would be careful with just continuously retrying.

Upvotes: 4

Related Questions