Two ajax requests on same event at same time . what should be the typical behaviour? how it is different if request is synchronous

后端 未结 4 2028
轻奢々
轻奢々 2020-12-31 20:40

In the following javascript code, I am sending two Ajax request at the same time.
After analysis using Firebug, I came to unusual conclusion that :
\"which ever

4条回答
  •  -上瘾入骨i
    2020-12-31 20:49

    Gaurav, you have an error, at the end of the 1st $.ajax it must end as ), and 2nd as ).

    You can't end with ;

    var result1;
    var result2;
    $.when(
        $.ajax({ // First Request
            url: form_url, 
            type: form_method,      
            data: form_data,     
            cache: false,
            success: function(returnhtml){     
                    result1 = returnhtml;                  
            }           
        }),
    
        $.ajax({ //Seconds Request
            url: form_url, 
            type: form_method,      
            data: form_data,     
            cache: false,
            success: function(returnhtml){                          
                result2 = returnhtml;     
            }           
        })
    
    ).then(function() {
        $('#result1').html(result1);
        $('#result2').html(result2);
    });

提交回复
热议问题