Jump to content
funbinod

send data to multiple pages using jquery ajax

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.

Share this post


Link to post
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.

Share this post


Link to post
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??

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...