在JavaScript中使用Webservice

时间:2014-10-06 02:25:52

标签: javascript web-services

现在,我想使用来自http://www.webservicex.net/globalweather.asmx的服务来通过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");
}  

0 个答案:

没有答案