Two $.post requests one after the other.Second $.post request doesn't get executed

前端 未结 1 1366
小蘑菇
小蘑菇 2020-11-22 12:29

I have a javascript function inside which i have two $.post requests.Both the $.post requests should get executed.But sometimes,second $.post request doesn\'t get executed.W

1条回答
  •  旧时难觅i
    2020-11-22 13:09

    $.post() is an abbreviated form of the $.ajax() structure. I usually prefer to use the $.ajax() structure because:

    • It's easier to see if I've missed anything
    • I can more easily add additional params, such as asynch: false,
    • When new to ajax I found it considerably easier to troubleshoot this structure

    In your case, you might find your problem easier to solve in a $.ajax() structure, since it would be easier to see that a second ajax call (that depends on the outcome of a first ajax call) must happen in the success function of the first ajax call.

    Here is a standalone example (too bad jsFiddle cannot handle ajax...):

    TESTER.PHP

    
        
            
    
            
        
    
    
        Email: 

    Password:


    yourphpfile.php

    Here is something new';
        echo $n;
    }
    

    0 讨论(0)
提交回复
热议问题