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) })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.