user319854
user319854

Reputation: 4106

jquery, wait for completed

how to run the second function only when the first will be completed in?

$(document).ready(function() {
 $("#first").load("first.php?id="+ Math.random());
 $("#second").load("second.php?id="+ Math.random());
});

Upvotes: 0

Views: 144

Answers (1)

David Hedlund
David Hedlund

Reputation: 129782

load() comes with a callback parameter:

$(document).ready(function() {
 $("#first").load("first.php?id="+ Math.random(), {}, function() {
  $("#second").load("second.php?id="+ Math.random());
 });
});

The {} is for passing an empty object to the data parameter.

Upvotes: 2

Related Questions