Jump to content

send data to multiple pages using jquery ajax


funbinod

Recommended Posts

hello all! greetings!

 

i'm learning jquery ajax. i understood how we send data to another page and get result from there. but i'm thinking if i can send same data to multiple pages or not.

 

please guide.

Link to comment
Share on other sites

You can send as many requests as you want. To do that in jQuery, just call $.ajax() more than once with different destination URLs.

Link to comment
Share on other sites

yes but, i thought, there could be some special method to send SAME DATA to multiple pages using single ajax request in stead of writing multiple ajax requests for SAME DATA. is there any special method??

Link to comment
Share on other sites

That's not how HTTP works. Each request would have a different response, so it has to be handled by a new XmlHttp object.

 

Store the data in a variable, use that same variable for multiple AJAX requests.

// This is the data we're going to send
var data = { name: "John", location: "Boston" }

// The response handler
var handler = function(response) {
  // DO something
}

// Send it to page 1
$.ajax({
  method: "POST",
  url: "page1.php",
  data: data,
  success : handler
})

// Send it to page 2
$.ajax({
  method: "POST",
  url: "page2.php",
  data: data,
  success : handler
})

// Send it to page 3
$.ajax({
  method: "POST",
  url: "page3.php",
  data: data,
  success : handler
})
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...