Its not jQueries fault. Its just what Javascript does.
If you look at the type of newVotes
you'll find its a string. ( typeof(newVotes)
).
The binary operators *
and -
convert their arguments to numbers.
The binary operator +
if either argument is a string converts the other arguments to strings. Otherwise it converts them to numbers.
So all you need to do is convert your data to a number in your success callback and all will work for you:
$.ajax({
type: 'POST',
url: 'forumvote.php',
data: {'timestamp' : timestamp, 'vote': vote},
success: function(data, textStatus) {
newvotes = parseFloat(data);
},
//dataType: 'text',
async:false,
});