2

我有两个单独的 Ajax Post 请求,我需要将它们加在一起,它们都链接到货币兑换提要,它基本上是从不同货币转换而来的两个值,然后在都转换为一种货币后需要加在一起,我让它们都使用相同的货币不,我只需将两个结果相加即可得到最终总数。

这是两个请求

    var dataString = "amount=" + entireTotal + "&from=" + from + "&to=" + to;
        //Lets Get the exchange rates from our total
     $.ajax({
       type: "POST",
       url: "http://fileserver/website/modules/mod_calculation/js/currency.php",
       data: dataString,
       success: function(data){
        $('#inputresult').show();
        //Put received response into result div
         $('#inputresult').html(data);
       }
     });

var dataString = "amount=" + amountGel + "&from=" + fromGel + "&to=" + toGel;
            $.ajax({
       type: "POST",
       url: "http://fileserver/website/modules/mod_calculation/js/currencygel.php",
       data:  dataString,
       success: function(data){
           $('#resultsgel').html(data);
         //Show results div
         $('#resultsgel').show();
        //Put received response into result div
       }
     });

任何帮助都会非常感激..谢谢:)

4

1 回答 1

2
var request1 = $.ajax({ ... }),
    request2 = $.ajax({ ... });

$.when(request1, request2).then(function(response1, response2) { ... })

进一步阅读:

类似于您需要的小抽象示例(抱歉,没有足够的时间在那里创建 ajax 请求,但它们的行为完全相同):http: //jsfiddle.net/Y26zd/

于 2012-10-01T10:15:11.833 回答