Perhaps this is a multiple url in the same ajax call?

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

Code example:

$.ajax({ type: 'POST', url: '../services/form_data.php', //can I send data to multiple url with same ajax call. data: { answer_service: answer, expertise_service: expertise, email_service: email, }, success: function (data) { $(".error_msg").text(data); } }); 
+8
javascript jquery ajax
source share
3 answers

You cannot use the same code for 1 request from many pages.

BUT you can send 2 requests. it can be done by copying your ajax code or by creating a function that receives a URL and sends a request with that URL.

 function sendMyAjax(URL_address){ $.ajax({ type: 'POST', url: URL_address, data: { answer_service: answer, expertise_service: expertise, email_service: email, }, success: function (data) { $(".error_msg").text(data); } }); }; 
+12
source share

All you need is $. each and two forms of the $ parameters . 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. Messages generated by the callback will be overwritten as shown. You probably want to use $ ('# someDiv'). Append () or the like in a function of success.

+8
source share

A single AJAX request can only process one URL, but you can create multiple AJAX requests for different URLs, and they will do their job at the same time - you won’t have to wait for one of them to complete before starting the next.

(If your URLs are on the same server, you might consider reorganizing your code on the server side so that a single URL does all the work that your multiple URLs do).

+3
source share

All Articles