添加两个单独的AJAX后rquest结果结合起来 [英] Adding two separate ajax Post rquest results together

查看:159
本文介绍了添加两个单独的AJAX后rquest结果结合起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立的Ajax POST请求,我需要加在一起,它们都链接到货币兑换饲料,从不同的货币会转换,然后需要在两个被转换成一前一后加在一起的两个基本价值货币,香港专业教育学院得到了他们两个在同一个货币不,我只需要两个结果加在一起以获得最终的总。

下面是两个请求

  VAR dataString =金额=+ entireTotal +&放大器;从=+在+&放大器;以=+到;
        //让我们获得汇率从我们的总
     $阿贾克斯({
       键入:POST,
       网址:HTTP://fileserver/website/modules/mod_calculation/js/currency.php
       数据:dataString,
       成功:功能(数据){
        $('#inputresult)显示()。
        //收到认沽反应到结果的div
         $('#inputresult')的HTML(数据)。
       }
     });

VAR dataString =金额=+ amountGel +&放大器;从=+ fromGel +&放大器;以=+ toGel;
            $阿贾克斯({
       键入:POST,
       网址:HTTP://fileserver/website/modules/mod_calculation/js/currencygel.php
       数据:dataString,
       成功:功能(数据){
           $('#resultsgel')的HTML(数据)。
         //显示结果DIV
         $('#resultsgel)显示()。
        //收到认沽反应到结果的div
       }
     });
 

任何帮助都将是多大的preciated ..谢谢:)

解决方案

  VAR request1 = $阿贾克斯({...}),
    请求2 = $阿贾克斯({...});

$。当(request1,请求2)。然后(函数(response1,响应2){...})
 

延伸阅读:

小抽象的例子类似,你需要什么(对不起,没有足够的时间来创建Ajax请求在那里,但他们的行为完全一样)的 http://jsfiddle.net/Y26zd/

I have two separate Ajax Post requests that i need to add together, they are both linking to a currency exchange feed, its basically two values that get converted from different currencies and then need to be added together after both being converted to one currency, ive gotten them both on the same currency no i just need to add the two results together to get a final total.

Here are the two requests

    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
       }
     });

any help at all will be much apreciated.. Thanks :)

解决方案

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

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

Further reading:

Small abstract example similar to what you need (sorry, don't have enough time to create ajax requests there, but they behave exactly the same): http://jsfiddle.net/Y26zd/

这篇关于添加两个单独的AJAX后rquest结果结合起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆