在JavaScript中使用Web服务

在JavaScript中使用Web服务,javascript,web-services,Javascript,Web Services,现在,我想使用来自的服务通过javascript获取天气。我尝试以下代码: var wsUrl = "http://www.webservicex.net/globalweather.asmx?op=GetWeather"; $.ajax({ type: "POST", url: wsUrl, contentType: "text/xml", dataType: "xml", data: soapRequest, success: process

现在,我想使用来自的服务通过javascript获取天气。我尝试以下代码:

var wsUrl = "http://www.webservicex.net/globalweather.asmx?op=GetWeather";

$.ajax({
    type: "POST",
    url: wsUrl,
    contentType: "text/xml",
    dataType: "xml",
    data: soapRequest,
    success: processSuccess,
    error: processError
});

        });
    });

function processSuccess(data, status, req) {
    if (status == "success")
        $("#response").text($(req.responseXML).find("GetWeatherResult").text());
}

function processError(data, status, req) {
    alert(req.responseText + " " + status);
    // alert("Error");
}  

var soapRequest='+$(“#txtName1”).val()+'+$(“#txtName2”).val()+''以什么方式不起作用?请描述这个问题。另外,代码应该放在问题中,而不是评论中。所有@David所说的,以及额外的
}是怎么回事s?请再次检查您的代码,我认为您错过了
var wsUrl…
之前的一些行。您可以在此处签入:@Krumia:当我运行此文件时,HTML出现错误:“XMLHttpRequest无法加载。请求的资源上不存在“访问控制允许源代码”头。因此不允许访问源代码“null”。“我无法修复它。。。