I want to do something similar to this - How to get “Data” field from xhr.responseText?
But in my case I want to extract the 'id' and the 'email' fields from the response text'.
I want to do something similar to this - How to get “Data” field from xhr.responseText?
But in my case I want to extract the 'id' and the 'email' fields from the response text'.
Seen as the response appears to be JSON, You would parse the response..
var j = JSON.parse(xhr.responseText);
//show header id
console.log(j.$id);
//show each email & id
j.Data.forEach(function (e) { console.log(e.email, e.$id); });
Steps to get id and email fields:
Parse the json:
var json = JSON.parse(xhr.responseText)
var data = json.Data
Here, data
is a javascript array :
[
{
$id: "2",
email: "anu@gmail.com"
},
{
$id: "3",
email: "anu@gmail.com"
}
]
For each object in the array, print $id
and email
:
data.forEach(function(datum) {
console.log('Id': datum.$id)
console.log('Email': datum.email)
})