【发布时间】:2019-08-14 21:37:46
【问题描述】:
我正在使用WCFStorm 来调试一个非常简单的 SOAP 端点:
http://www.dneonline.com/calculator.asmx?WSDL
可以使用这样的端点来请求 4 个基本算术计算并检索响应:在示例中,我请求数字 3 和 5 并收到响应 8,一切都很好!
我现在想创建一个无需使用 WCFStorm 即可完成相同任务的 HTML 页面。这是我的代码:
<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.dneonline.com/calculator.asmx?WSDL";
var soapRequest = '<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> <getQuote xmlns:impl="http://www.dneonline.com/calculator.asmx?WSDL"> <intA>' + $("#intA").val() + '</intA> <intB>' + $("#intB").val() + '</intB> </getQuote> </soap:Body></soap:Envelope>';
alert(soapRequest)
$.ajax({
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError
});
});
});
function processSuccess(data, status, req) {
alert('success');
if (status == "success")
$("#response").text($(req.responseXML).find("Int32").text());
alert(req.responseXML);
}
function processError(data, status, req) {
alert('err' + data.state);
//alert(req.responseText + " " + status);
}
</script>
</head>
<body>
<h3>
Calling Web Services with jQuery/AJAX
</h3>
Enter the numbers:
<input id="intA" type="string" />
<input id="intB" type="string" />
<input id="btnCallWebService" value="Call web service" type="button" />
<div id="response"></div>
</body>
</html>
但不幸的是,我只能收到一个:errundefined。
我哪里错了?
【问题讨论】:
-
转储所有的值数据、状态、请求,看看你在控制台中得到了什么