Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why jQuery rounds value?

Using ajax i request a authenticationID like this: enter image description here


This is wrong because the real HTTP-Transfer is this:

enter image description here

(By the way: response-type is "application/json;charset=UTF-8")

I see a clash between

-1369082024195183657 and 
-1369082024195183600

How to prevent the rounding or is it a bug?

like image 591
Grim Avatar asked Oct 18 '22 09:10

Grim


1 Answers

jQuery tries to parse the HTTP response as integer based on the JSON content-type.

> JSON.parse("-1369082024195183657")
-1369082024195183600

You can override it by telling jQuery you expect a string by setting the dataType property in $.ajax configuration:

$.ajax({ 
   dataType : "text", 
   url : "rest/Registration",
   success : function(data){
       // data should be "-1369082024195183657"
   }
})

I guess you don't need to do any arithmetic operations on an authenticationID token, so you can just keep it as a string.

like image 111
pawel Avatar answered Oct 21 '22 05:10

pawel