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 🙂
Further reading:
A good article about how to use promises in jQuery: http://joseoncode.com/2011/09/26/a-walkthrough-jquery-deferred-and-promise/
And the official documentation pages.
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/