javascript - Parse json array getting certain index -


i'm new jquery , javascript, using ajax upload image , wish image url, tried getting it, keep getting error time. can me out this? thanks!

error received:

uncaught typeerror: cannot read property 'length' of undefined 

here result after calling url:

{"status_code":200,"status_txt":"ok","data":{"img_name":"nffwv.jpg","img_url":"http:\/\/sl.uploads.im\/nffwv.jpg","img_view":"http:\/\/uploads.im\/nffwv.jpg","img_width":"3840","img_height":"2160","img_attr":"width=\"3840\" height=\"2160\"","img_size":"3.1 mb","img_bytes":3226508,"thumb_url":"http:\/\/sl.uploads.im\/t\/nffwv.jpg","thumb_width":360,"thumb_height":203,"source":"base64 image string","resized":"0","delete_key":"338aa524f1654056"}} 

and here code:

var imgfile = $('#receipt').get(0).files[0];         $.ajax({             type: 'post',             url: 'http://uploads.im/api?upload='+imgfile,             datatype: 'json',             data:formdata,             cache: false,             contenttype: false,             processdata: false,             success: function(data){                 var htmlstr = '';     $.each(data, function(k, v){         $.each(v.data, function(s, a){         htmlstr +=  a.img_url + '<br />';         });    });    alert(htmlstr);             }              }); 

if want access individual property of returned json,then can in way.

var imgobj = data.data // response in success callback var imgname = imgobj.img_name; var imgurl= imgobj.img_url;  // in way can access rest of property 

there no need of kind of loop $.each


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -