I’m having trouble to sum two different kinds of values. I have one value that I get from a json request like so:
function bakVormShipping(targetClass){
$.getJSON('http://shop.com/cart/?format=json', function(data){
$.each(data.cart.shipping.methods, function(index, methods){
if (index == "core|10292|40695" || index == "core|10292|40693" || index == "core|10292|40718"){
$('<strong/>').html('€' + (+methods.price.price_incl).toFixed(2)).appendTo(targetClass); // this is value 1
}
});
});
}
The other value is in a div somewhere in a html page, like so:
<div class="total">Totaal (incl.btw):
<span class="grandTotal">
{{ page.cart.total.price | money }} // this is value 2
</span>
</div>
Is it even possible to sum these two values? If so can somebody please give me some examples or maybe some directions? I’ve tried numerous things with parseFloat etc. but it returns nothing, NaN or undefined. So some help is more then welcome 🙂
Please don’t do a price calculation on the client side (“never trust a client”, because they can be hacked. For that reason, you end up duplicating code on the client and server side).
Instead, look into using Ajax to call back to the server for recalculations, and updates to the web page, as necessary.
http://en.wikipedia.org/wiki/Ajax_(programming)
http://api.jquery.com/category/ajax/
If the server isn’t currently performing all calculations you need, the only safe way to fix the problem is to modify the server code.