2017-10-28 63 views
0

我將根據發佈的數據獲取此對象。用戶在數據中選擇不同的過濾器。當用戶選擇不同的過濾器時,我想更新postThis Object並使用更新後的對象再次進行Ajax調用。成功更新數據後再次進行ajax POST調用

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 

}) 

回答

0

很簡單的方式做到這一點很簡單巢AJAX調用

$.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) { 
    [...] 
    }) 
}) 
1

如果你只是想發在第一個成功,與第一請求的結果的情況下,另一種AJAX請求那麼只需再次提出$.ajax請求就像你已經有,並通過它接收到的數據:

$.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 
    }) 
} 
相關問題