javascript - Reading JSON data with jquery. Uncaught SyntaxError: Unexpected token : -
i'm trying read json data using jquery. i'm trying read json url: http://mkweb.bcgsc.ca/color-summarizer/?url=http://scontent-a.cdninstagram.com/hphotos-xfa1/t51.2885-15/10643840_701797013239098_657737630_a.jpg&precision=low&num_clusters=3&json=1&callback=?
keep getting error: uncaught syntaxerror: unexpected token :
here jquery:
$(document).ready(function () { var 1 = "1" $.getjson('http://mkweb.bcgsc.ca/color-summarizer/?url=http://scontent-a.cdninstagram.com/hphotos-xfa1/t51.2885-15/10643840_701797013239098_657737630_a.jpg&precision=low&num_clusters=3&json=1&callback=?', function(result) { document.write(result.clusters.one.rgb[0]); }); });
i'm getting error @ first colon in json code.
understand, json data being read javascript. how can fix this.
reading api docs found need specify jsnop=1
parameter in order retrieve data via jsonp.
tthe correct code this:
$(document).ready(function () { $.ajax({ url: 'http://mkweb.bcgsc.ca/color-summarizer/', type: 'get', datatype: 'jsonp', jsonpcallback: 'colorsummary', data:{ url: 'http://scontent-a.cdninstagram.com/hphotos-xfa1/t51.2885-15/10643840_701797013239098_657737630_a.jpg', precision: 'low', num_clusters: '3', jsonp: '1' }, success: function(result){ document.write(result.clusters['1'].rgb[0]); } }); });
i structured request can change parameters easily.
ps: watch out json notation ( ['1'] in clusters , so)
Comments
Post a Comment