Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  55] [ 7]  / answers: 1 / hits: 18183  / 12 Years ago, sat, june 9, 2012, 12:00:00

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?


More From » jquery

 Answers
100

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):




Every attempt is made to convert the string to a JavaScript value
(this includes booleans, numbers, objects, arrays, and null) otherwise
it is left as a string. To retrieve the value's attribute as a string
without any attempt to convert it, use the attr() method.



[#85035] Friday, June 8, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeremiahianx

Total Points: 629
Total Questions: 106
Total Answers: 112

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
;