TheMeisterSE
TheMeisterSE

Reputation: 541

Load file when another load is done

So I basically have a load that loads the file to an id and when that load is done I want to load another file to an id which is inside the first load.

Does it sound a bit weird?

We can add a bit of code to describe it easier.

function interestsList() {
$('.interests_editlist').fadeIn(500).load('/snippets/interests_edit.php');
}

That is how it looks right now. I want to add this line

$('#interests_list').load('/snippets/interests_list.php');

but if I just add it, it doesn't load. The reason might be that it tries to load before the load above is done. That is a problem because #interests_list is loaded with the first load.

How do I make the second load to start loading when the first one is finished?

Upvotes: 2

Views: 62

Answers (2)

A. Wolff
A. Wolff

Reputation: 74420

load() method accept a complete callback:

function interestsList() {
    $('.interests_editlist').fadeIn(500)
        .load('/snippets/interests_edit.php', function () {
        $('#interests_list').load('/snippets/interests_list.php');
    });
}

Upvotes: 2

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

you can use .load() callback to know when load is complete try this:

    function interestsList() {
       $('.interests_editlist').fadeIn(500).load('/snippets/interests_edit.php', function() {
           //callback function when the first load is complete
           $('#interests_list').load('/snippets/interests_list.php');
      });
    }

Upvotes: 1

Related Questions