我无法从 JQuery 调用 Web 服务。
我正在访问的网址是:http://www.deeptraining.com/webservices/weather.asmx?WSDL
其中有一个名为GetWeather
. 我正在使用 Firefox,我收到以下消息:
Firefox 控制台:[19:43:29.849] 选项 http://www.deeptraining.com/webservices/weather.asmx?op=GetWeather [HTTP/1.1 200 OK 371ms]
警报:未定义的解析器错误
如果获取代码200,表示请求发送成功?我究竟做错了什么?提出请求的正确方法是什么?谢谢!!
这是我的代码:
<html>
<head>
<title>Calling Web Service from jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnCallWebService").click(function (event) {
var wsUrl = "http://www.deeptraining.com/webservices/weather.asmx?op=GetWeather";
var soapRequest ='<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<GetWeather xmlns="http://litwinconsulting.com/webservices/"> \
<City>new york</City> \
</GetWeather> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError
});
});
});
function processSuccess(data, status, req) {
if (status == "success")
alert('SUCCESS');
}
function processError(data, status, req) {
alert(req.responseText + " " + status);
}
</script>
</head>
<body>
<h3>
Calling Web Services with jQuery/AJAX
</h3>
<input id="btnCallWebService" value="Call web service" type="button" />
<div id="response" />
</body>
</html>