Buongiorno, ho un problema in un file .html che, grazie ad una richiesta con XMLHttpRequest(), preleva dei dati da un server che lavora con il protocollo XML-RPC. Ora, io gli passo una stringa, che è quella che questo server vuole come parametro e successivamente il server mi risponde correttamente con un xml e al suo interno un json, contenente tutti i dati che mi servono. Ma come faccio a prelevare quei dati del JSON che a me servono?
Lascio il codice...
function invia(){
var request_xml = '<?xml version="1.0"?><methodCall><methodName>Comitato</methodName><params><param><value><string>username</string></value></param><param><value><string>pwd</string></value></param></params></methodCall>';
request_xml = request_xml.replace("username", user);
request_xml = request_xml.replace("pwd", pwd);
var res = encodeURIComponent(request_xml);
var http = new XMLHttpRequest();
var url = "qui c'è l'url del sito che però non scrivo ";
var params = "request_xml="+encodeURIComponent(res);
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
//Call a funct ion when the state changes.
if(http.readyState == 4 && http.status == 200) {
if(!http.responseText.includes("null")){
messaggio.innerHTML = "OK! Accesso effettuato correttamente";
var radice = http.responseText;
console.log(radice);
}
else{
alert("Errore nella richiesta");
}
}
}
http.send(params);
}
Quel famoso console.log(radice) ritorna questo:
<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
<param>
<value>
<string>{
" ; id " : " 21 " ,
" ; id_comitato " : " 22 " ,
" ; auth " : " 3 " ,
" ; comitato " : " COMITATO TEST " ,
" ; nome " : " Operatore Test "}</string>
</value>
</param>
</params>
</methodResponse>
Questo è un JSON ma come faccio a prendere i valori?(Non preoccupatevi dei numeri strani