Note that there are some explanatory texts on larger screens.

plurals
  1. POError when consuming a web service with JavaScript
    primarykey
    data
    text
    <p>I am trying to consume a web service ( <a href="http://www.webservicex.net/CurrencyConvertor.asmx?wsdl" rel="nofollow">http://www.webservicex.net/CurrencyConvertor.asmx?wsdl</a> ) using JavaScript:</p> <pre><code>&lt;script type="text/javascript"&gt; function soap() { var xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', 'http://www.webservicex.net/CurrencyConvertor.asmx?wsdl',true); var sr = '&lt;?xml version="1.0" encoding="utf-8"?&gt;' + '&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/"&gt;'+ '&lt;soapenv: Header/&gt;'+ '&lt;soapenv: Body&gt;'+ '&lt;web:ConversionRate&gt;'+ '&lt;web:FromCurrency&gt;EUR&lt;/web:FromCurrency&gt;'+ '&lt;web:ToCurrency&gt;TND&lt;/web:ToCurrency&gt;'+ '&lt;/web:ConversionRate&gt;'+ '&lt;/soapenv: Body&gt;'+ '&lt;/soapenv:Envelope&gt;'; xmlhttp.onreadystatechange = function (e) { alert('onready'); if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { alert('done use firebug to see response'); } } if (xmlhttp.readyState == 0) { alert('open() has not been called yet'); } if (xmlhttp.readyState == 1) { alert('send() has not been called yet'); } if (xmlhttp.readyState == 2) { alert('send() has been called, ...'); } if (xmlhttp.readyState == 3) { alert('Interactive - Downloading'); } else alert('Consuming Error '+e.message); } // Send the POST request xmlhttp.setRequestHeader("SOAPAction", "http://www.webservicex.net/CurrencyConvertor/"); xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.send(sr); alert("Hi WS"); // send request // ... } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;input type="button" value="WS" onclick="soap();"&gt; &lt;/form&gt; &lt;/form&gt; </code></pre> <p>In the execution I got the different messages mentioned in the <code>onreadystatechange()</code> function (even the error one!) but I couldn't know how to get the answer returned by the web service (I tried with this line <code>alert(xmlhttp.responseXML);</code> but in vain ), I don't know if I am doing it right and how to display the web service reply.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload