Mianowicie mam problem z przetworzeniem danych z serwera po wysłaniu żądania GET.
Mój Kod wygląda tak:
CODE
function httpGet(theUrl){
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, true);
xmlHttp.onreadystatechange = handleReadyStateChange;
xmlHttp.send(null);
function handleReadyStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
document.getElementById("response").innerHTML=xmlHttp.responseText;
}
}
}
}
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, true);
xmlHttp.onreadystatechange = handleReadyStateChange;
xmlHttp.send(null);
function handleReadyStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
document.getElementById("response").innerHTML=xmlHttp.responseText;
}
}
}
}
ta funkcja działa mi bez zarzutu. Robię requesta do strony i wynik wyświetal mi się na stronie w postacji takiej:
{ "id": "1388744431444806" }
i to jest obiekt, albo JSON.
Chciałbym pobrać zawartość ID i przypisać do jakieś zmien
Próbowałem przez return w funkcji i później przypisać to do jakieśzmiennej podczas wywołania i odwołać się do właściwości ID, ale gdy próbuje wyświetlić to undefined mam ;/
Kto wie jak pobrać zawrtość właściwości id?