使用JavaScript使用web服务时出错

使用JavaScript使用web服务时出错,javascript,web-services,xmlhttprequest,Javascript,Web Services,Xmlhttprequest,我正在尝试使用JavaScript使用web服务(): <script type="text/javascript"> function soap() { var xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', 'http://www.webservicex.net/CurrencyConvertor.asmx?wsdl',true); var sr = '<?xml

我正在尝试使用JavaScript使用web服务():

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

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open('GET', 'http://www.webservicex.net/CurrencyConvertor.asmx?wsdl',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 (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
        // ...
    }

</script>
</head>

<body>
<form>
            <input type="button" value="WS" onclick="soap();">
        </form>
</form>

函数soap(){
var xmlhttp=new XMLHttpRequest();
open('GET','http://www.webservicex.net/CurrencyConvertor.asmx?wsdl",对),;
var sr=
'' +
''+
''+
''+
''+
“欧元”+
“TND”+
''+
''+
'';
xmlhttp.onreadystatechange=函数(e){
警报(“onready”);
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
警报(“使用firebug查看响应完成”);
}
}
if(xmlhttp.readyState==0){
警报('尚未调用open()');
}
if(xmlhttp.readyState==1){
警报('send()尚未调用');
}
if(xmlhttp.readyState==2){
警报('send()已被调用,…);
}
if(xmlhttp.readyState==3){
警报(“交互式下载”);
}
其他的
警报(“消费错误”+e.message);
}
//发送POST请求
setRequestHeader(“SOAPAction”http://www.webservicex.net/CurrencyConvertor/");
setRequestHeader('Content-Type','text/xml');
xmlhttp.send(sr);
警报(“Hi-WS”);
//发送请求
// ...
}

在执行过程中,我得到了
onreadystatechange()
函数中提到的不同消息(甚至是错误消息!),但我不知道如何获得web服务返回的答案(我尝试了这一行
alert(xmlhttp.responseXML);
但没有成功),我不知道我做得是否正确,以及如何显示web服务回复。

由于本主题()中的限制,您将无法使用该web服务,我应该创建一个名为processRequest的函数。在这里,您应该检查xmlHttp.readyState是否为4。如果不是,只需等待再次调用该函数。这是stronge,因为我多次(不是一次)显示警报,最后我得到了错误。你有解决这个问题的办法吗?我想使用这个web服务。谢谢