javascript - jQuery ajax method with dataType 'json' incorrectly parsing json data -
i'm having inexplicable behaviour using jquery 1.4.2, , i'm beginning think might safari problem, not jquery one. let me explain.
i began enough using .getjson this:
$.getjson("/challenge/results", form_data, function(data){ //i know console.log bad news, simplification. console.log('data', data); }
and log gave me along lines of
>locations: array (1)
while expecting array of size 2. had @ json in response:
{"locations": [{"customer_id":2,"editable":true,"id":971,"latitude":43.659208,"longitude":-79.407501,"max_zoom":25,"min_zoom":9,"name":"test"}, {"customer_id":3,"editable":true,"id":974,"latitude":36.746944,"longitude":-107.970899,"max_zoom":25,"min_zoom":9,"name":"test2"}]}
i've simplified considerably sake of clarity, far can tell, json received valid (generated programmatically through rails). [update: jsonlint confirms hypothesis.]
i surprised this, converted request $.ajax request see if there subtle difference between them (since then, looking in source of jquery see $.getjson calls $.ajax).
$.ajax({ url:"/challenge/results", datatype: 'json', data: form_data, cache:false, success: function(data, textstatus){ console.log("data!", data, textstatus); });
but alas! same response:
locations: array (1) success
at point, must admit - getting bit silly, thought try bound fail:
$.ajax({ url:"/challenge/results", datatype: 'text', data: form_data, cache:false, success: function(data, textstatus){ console.log("parsed:!", $.parsejson(data), textstatus); });
much surprise console read:
locations: array (2) success
i stumped. @ point dug in heels , took long hard @ jquery source (1.4.2). suppose unsurprisingly, ajax function seems not handle json parsing (although, must admit, can't sure).
i'm totally @ loss why happening - appreciated.
perhaps missed something, notice json object has single property ("locations"
) array it's value. have tried:
$.getjson("/challenge/results", form_data, function(data){ //i know console.log bad news, simplification. console.log('data', data.locations); }
Comments
Post a Comment