I have a MySQL BIGINT that I am storing in HTML5 data. Then I’m trying to access that value and pass it through an AJAX call.
<div data-id="211285677671858177">
And the JavaScript:
var send_data = {
id: '' + $(this).data('id')
}
$.post('/send.php', send_data);
The issue is that the jQuery data function seems to retrieve that value as a floating point and not a string. So appending it to a blank string isn’t helping because it’s already too late – it’s already been rounded (in this case to 211285677671858180). What can I do to fix this?
This isn’t a case of “long int” really, the number you’re getting is the closest available representation as a floating-point number.
Anyway, you want the value as a string. Quote the jQuery docs for
.data(emphasis mine):