Ordering of asynchronous javascript events

前端 未结 3 1467
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 11:47

I have the following code:

$(\"#submit_financials\").live(\'click\', function(event){
    event.preventDefault();

    // using serialize here to pass the POST v         


        
3条回答
  •  忘掉有多难
    2021-01-22 12:36

    You can try using deferred objects If you want to generate graph before alert but want both calls to be completed.

    $.when (
       $.post("/ajax/custom_filter/", serialized_data),
       $.post("/ajax/force_download/", serialized_data)
    ).done(function(a1,  a2){
        /* a1 and a2 are arguments resolved for the 
        custom_filter and force_download post requests  */
       var customFilterResponse = a1[2]; 
       /* arguments are [ "success", statusText, jqXHR ] */
    
       //generate graph.
    
       alert('hello');
    });
    

提交回复
热议问题