Javascript web服务的执行不会';我不能在HTML中工作

Javascript web服务的执行不会';我不能在HTML中工作,javascript,Javascript,我试图通过以下代码测试一个使用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 =

我试图通过以下代码测试一个使用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>

函数soap(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open('POST','http://www.webservicex.net/CurrencyConvertor.asmx",对),;
var sr=
'' +
''+
''+
''+
''+
“欧元”+
“TND”+
''+
''+
'';
xmlhttp.onreadystatechange=函数(){
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){
警报(“交互式下载”);
}
其他的
警报(“消费错误”);
}
//发送POST请求
setRequestHeader('Content-Type','text/xml');
xmlhttp.send(sr);
//发送请求
// ...
}
问题是没有显示任何内容(我谈论的是不同的警报),并且“onreadystatechange”函数没有执行

我不知道原因是什么?
提前谢谢

除非外部服务器发送CORS头,否则无法发送跨域AJAX请求。在开发人员控制台中看一看,它会显示一个错误。你调用过这个函数吗?你真的调用过soap()函数吗?当我运行它时,我收到两个警报:“send()已被调用,…”和“Consuming Error”。这也是一个关于跨域请求的有效注释。是的,我已经用以下形式调用了soap()函数:但没有结果!顺便说一句,IDE控制台(我使用Tizen IDE)中没有错误消息,即使使用CORS头,当从磁盘提供页面时,大多数浏览器都不允许CORS请求。您需要在服务器上提供该页面。有些浏览器甚至更进一步,如果服务器由localhost或127.0.0.1提供服务,则拒绝允许CORS请求,因此您需要给它一个域名(通常通过编辑主机文件)