Visualizzazione dei risultati da 1 a 2 su 2

Visualizzazione discussione

  1. #1

    MXLRequest , XML e JSON

    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>{
    &#34 ; id " : " 21 " ,
    &#34 ; id_comitato " : " 22 " ,
    &#34 ; auth " : " 3 " ,
    &#34 ; comitato " : " COMITATO TEST " ,
    &#34 ; nome " : " Operatore Test "}</string>
    </value>
    </param>
    </params>
    </methodResponse>

    Questo è un JSON ma come faccio a prendere i valori?(Non preoccupatevi dei numeri strani
    Ultima modifica di LorenzoCabutto; 15-04-2018 a 15:27

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.