I am using Jquery.Ajax and want to do some addition with the ajax response and predefined variable. My code is as follows –
success: function(response)
{
$('#net_amount').html("$"+(credit+response));
}
Assuming ‘response’ as 10 and ‘credit’ as 20, it prints 2010. I want it to be 30 (20+30).
What shall I do ?
Because
+is used for concatenation in javascript as well as the addition, you need to ensure the type of your variables is numerical, not a string.Your options are to use
parseInt()andparseFloat(). I would suggest the latter as you are dealing with monetary values in your example.