Hello. The task is this: there is a script, after processing the data, it returns data. Upon receipt, you need to process them. I usually watch them through console.log (file). An array of data arrives (shown in screen 1.). I need to get data from the file.xhr.response section. I am writing console.log (file.xhr.response); in response to silence. What could be the reason, perhaps this level should be addressed somehow differently. For example, I write console.log (file.xhr); an array with xhr data is displayed ... (screen 2), but it is impossible to go further down. How to get to this level? Thank you in advance!

Screen 1 Screen 2

Reported as a duplicate by vp_arth , user207618, Grundy members javascript 21 Mar '17 at 19:56 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    In xhr , the response is always a string, it needs to be parsed.

     var res = JSON.parse(file.xhr.responseText) console.log(res.name); 

    Well, and perhaps you are not waiting for the server to respond?

     file.xhr.onload = function() { var res = JSON.parse(file.xhr.responseText) console.log(res.name); }; 

    The fact is that the value of the object in the console is displayed at the time of its disclosure (this is indicated by the blue letter i ), you click at the moment when the answer is already received and see it, but when you call console.log, it is still empty.

    • one
      The first option is not working, I, too, "detained", and the second is what we need! Great. You saved me time, THANKS! - Eugene