Multiple url in same ajax call?is this possible?

后端 未结 4 1052
忘了有多久
忘了有多久 2020-12-01 11:16

Can I send my data to multiple pages using ajax call? I dont want to use another ajax call for this.

Sample code:

 $.ajax({
     type: \'POST\',
             


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 11:57

    All you need is $.each and the two parameter form of $.ajax

    var urls = ['/url/one','/url/two', ....];
    
    $.each(urls, function(i,u){ 
         $.ajax(u, 
           { type: 'POST',
             data: {
                answer_service: answer,
                expertise_service: expertise,
                email_service: email,
             },
             success: function (data) {
                 $(".error_msg").text(data);
             } 
           }
         );
    });
    

    Note: The messages generated by the success callback will overwrite each other as shown. You'll probably want to use $('#someDiv').append() or similar in the success function.

提交回复
热议问题