jquery - Ordering of asynchronous javascript events -


i have following code:

$("#submit_financials").live('click', function(event){     event.preventdefault();      // using serialize here pass post variables django view function     var serialized_data = $("#financials_filter_form").serialize()      $.post("/ajax/custom_filter/", serialized_data, function(response){         // create graph     });     $.post("/ajax/force_download/", serialized_data, function(response){         alert('hello');     });  }); 

however, when code, response 'hello' before graph. why happening? , how change such graph first?

async, can never know function runs\ finish first...

think on async operations telling group of people run 1 mile, know finish first? (yes, jon skeet, chuck norris...)

you can use callack run second ajax:

$.post("/ajax/custom_filter/", serialized_data, function(response) {     // create graph     ...     ...      $.post("/ajax/force_download/", serialized_data, function(response) {         alert('hello');     }); });​ 

Comments