Make sure first ajax function finishes before second one

前端 未结 9 1448
無奈伤痛
無奈伤痛 2021-01-18 01:41

I have a JavaScript function that makes two consecutive Ajax requests using jQuery. I want to make sure that the first request has loaded before the second function is call

9条回答
  •  自闭症患者
    2021-01-18 02:04

    Using jQuery the simplest way is like this:

     $.ajax({
       type: "POST",
       url: "some.php",       
        success: function(msg){
           $.ajax({
             type: "POST",
             url: "some2.php",
    
             success: function(msg){
                 alert( "End of second call" );
             }
          });
        }
     });
    

提交回复
热议问题