john
john

Reputation: 27

Make a ajax POST call again after the data in success is updated

I will get the object here based on the data posted. User chooses different filters in data. As user chooses different filters, I want to update the postThis Object and make the Ajax call again with updated object.

var postThis = {
  "name": ''
}
$.ajax({
  method:post,
  url:someurl,
  data: postThis
})
.success(function(data) {
  // name has to be updated with value which I get after user chooses it

}) 

Upvotes: 0

Views: 2001

Answers (2)

linasmnew
linasmnew

Reputation: 3977

If you just want to send another AJAX request in the case where the first one succeeds, with results of the first request then just make another $.ajax request like you already have, and pass it the received data:

$.ajax({
  method: post,
  url: someurl,
  data: postThis
})
.success(function(data) {
  yourSecondAjaxCall(data);
})

function yourSecondAjaxCall(dataFromFirstAjax) {
  $.ajax({
    method: post,
    url: someurl,
    data: dataFromFirstAjax
  })
  .success(function(data) {
     // do whatever
  })
}

Upvotes: 2

alfredopacino
alfredopacino

Reputation: 3241

The very simple way to do that is simply nest ajax calls

$.ajax({
  method:post,
  url:someurl,
  data: postThis
})
.success(function(data) {
  // name has to be updated with value which I get after user chooses it
      $.ajax({
      method:post,
      url:someurl,
      data: UPDATED_DATA
    })
    .success(function(data) {
    [...]
    }) 
}) 

Upvotes: 0

Related Questions