我無法從JQuery調用Web服務。無法使用JQuery調用Web服務
我正在訪問的網址是:http://www.deeptraining.com/webservices/weather.asmx?WSDL
,它有一個名爲GetWeather
的操作。 我使用Firefox和我得到以下信息:
火狐控制檯:[19:43:29.849] OPTIONS http://www.deeptraining.com/webservices/weather.asmx?op=GetWeather [HTTP/1.1 200 OK 371ms]
提醒:未定義parsererror
如果獲得代碼,這意味着請求已成功發送? 我在做什麼錯?什麼是提出請求的正確方法? 謝謝!
這裏是我的代碼:
<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>
你們的這個HTML,你在'HTTP服務器部署? – acdcjunior