-1

I'm triying to post web service. But i want to get response value. My code is shown below:

 var xmlhttp = new XMLHttpRequest();
        xmlhttp.open('POST', 'http://www.w3schools.com/webservices/tempconvert.asmx',  true);

        // build SOAP request
        var sr =
            '<soapenv:Envelope' + ' ' +
                'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
                'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
                '<soapenv:Body>' +
                    '<CelsiusToFahrenheit  xmlns="http://tempuri.org/">' +
                    '<Celsius>44</Celsius>' +
                    '</CelsiusToFahrenheit>'+
                '</soapenv:Body>' +
            '</soapenv:Envelope>';

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {

                    alert('done use firebug to see response');
                }
            }
        }
        // Send the POST request
        xmlhttp.setRequestHeader('Content-Type', 'text/xml');
        xmlhttp.send(sr);

When i look in firebug, i realized web server response value is:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CelsiusToFahrenheitResponse xmlns="http://tempuri.org/"><CelsiusToFahrenheitResult>111.2</CelsiusToFahrenheitResult>   </CelsiusToFahrenheitResponse></soap:Body></soap:Envelope> 

But i dont know how can i get 111.2 value?

ftdeveloper
  • 1,053
  • 3
  • 26
  • 50
  • 1
    relevant source of code: http://stackoverflow.com/a/11404133/2022183 . please tell us what you tried to do already, so we can give assistance with that. – thriqon Jul 29 '13 at 10:27

1 Answers1

1

You are getting an xml response from your ajax call. Do do it correctly, you need to parse the xml code.

You can do easily it with jQuery:

var r = $(this.responseText).find("CelsiusToFahrenheitResult").text();
Sebastien
  • 682
  • 1
  • 14
  • 26