Wie man "Daten" - Feld von xhr.responseText?

Habe ich XMLHttpRequest() Funktion unten

var searchFriendRequests = function (userid) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://localhost:6344/api/Registeration/searchFriendrequests?userid=' + userid, false);
    xhr.setRequestHeader("Content-Type", "text/xml");
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                var data = xhr.responseText;
            }
        }
    };
    xhr.send(null);
}

wo xhr.responseText liefert den Wert als

{
    "$id": "1",
    "ContentEncoding": null,
    "ContentType": null,
    "Data": [
        {
            "$id": "2",
            "email": "[email protected]"
        },
        {
            "$id": "3",
            "email": "[email protected]"
        }
    ],
    "JsonRequestBehavior": 1,
    "MaxJsonLength": null,
    "RecursionLimit": null
}

Wie bekomme ich die Data Feld aus der responseText?

InformationsquelleAutor der Frage Midhuna | 2014-07-03

Schreibe einen Kommentar