0

我正在尝试通过以下代码测试在 HTML 和 JavaScript 中使用 Web 服务 (SOAP) 的示例:

<script type="text/javascript">
   function soap() {

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open('POST', 'http://www.webservicex.net/CurrencyConvertor.asmx', true);


var sr =
       '<?xml version="1.0" encoding="utf-8"?>' +
       '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">'+
       '<soapenv:Header/>'+
        '<soapenv:Body>'+
        '<web:ConversionRate>'+
     '<web:FromCurrency>EUR</web:FromCurrency>'+
     '<web:ToCurrency>TND</web:ToCurrency>'+
        '</web:ConversionRate>'+
        '</soapenv:Body>'+
        '</soapenv:Envelope>';

xmlhttp.onreadystatechange = function () {

            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');
        }
        // Send the POST request
        xmlhttp.setRequestHeader('Content-Type', 'text/xml');
        xmlhttp.send(sr);
        // send request
        // ...
    }
</script>

问题是什么都没有显示(我谈论不同的警报),并且没有执行“onreadystatechange”函数!

我没弄清楚原因?提前致谢!

4

0 回答 0