javascript - Accessing a value in nested JSON objects and arrays -


i'm using blueimp's jquery file upload plugin, , upon successful upload callback function is:

$('#fileupload').fileupload('send', {files: fileslist})     .success(function (result, textstatus, jqxhr) { console.log('success'); })     .error(function (jqxhr, textstatus, errorthrown) { console.log('error'); })     .complete(function (result, textstatus, jqxhr) {          console.log('complete: ' + json.stringify(result));         console.log(result.responsetext.files[0].name); }); 

so i'm looking @ .complete function. first console.log returns:

complete: {"readystate":4,"responsetext":"{"files":[{"name":"video.mp4","type":"video/mp4","size":2348842}]}","responsejson":{"files":[{"name":"video.mp4","type":"video/mp4","size":2348842}]},"status":201,"statustext":"created"} 

complete technically result, , under responsetext , under files, array, , name key/property in array.

so when try console.log result.responsetext.files[0].name, says uncaught typeerror: cannot read property '0' of undefined.

could please find what's wrong? thanks!

result.responsetext string

you need convert object: json.parse(result.responsetext)

response = json.parse(result.responsetext); console.log(response.files[0].name); 

will work


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -