有很多问题看起来像我的,例如:This one ,和This one ,但他们不是。
有人能给我一个发送数字并显示响应的 HTML 示例吗?我需要它在我的 HTML 应用程序中实现。
例如:
发送:8
返回:16
提前致谢。
应发送请求的 HTML 应用程序
<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript">
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://192.168.0.251:9080/wsa/wsa1/wsdl?targetURI=urn:services-progress-com:sys:server', true);
// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:services-progress-com:sys:server:Estagio"> ' +
'<soapenv:Header/> ' +
'<soapenv:Body> ' +
'<urn:lnestagio> ' +
'<urn:vvalor>5</urn:vvalor> ' +
'</urn:lnestagio> ' +
'</soapenv:Body> ' +
'</soapenv:Envelope> ';
xmlhttp.onreadystatechange == function () {
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert('done use firebug to see response');
}
}
};
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
window.xmlhttp = xmlhttp;
}
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Soap" onclick="soap();" />
</div>
</form>
</body>
<html>
WSDL 请求/响应
OBS.:我收到了来自 SoapUI 5.0.0 的请求/响应
<!--SOAP Request-->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:services-progress-com:sys:server:Estagio">
<soapenv:Header/>
<soapenv:Body>
<urn:lnestagio>
<urn:vvalor>8</urn:vvalor>
</urn:lnestagio>
</soapenv:Body>
</soapenv:Envelope>
<!--SOAP Request-->
<!--SOAP Response-->
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<lnestagioResponse xmlns="urn:services-progress-com:sys:server:*emphasized text*Estagio">
<result xsi:nil="true"/>
<vcalc>16</vcalc>
</lnestagioResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<!--SOAP Response-->
这是另一个例子:(但它有效......)
<!--I would like to do something like this, Must I create this ".asmx"? how to do it and where must I put this-->
<form action='http://www.w3schools.com/webservices/tempconvert.asmx/FahrenheitToCelsius'
method="post" target="_blank">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td>
<input class="frmInput" type="text" size="4" name="Fahrenheit">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="submit" value="Submit" class="button">
</td>
</tr>
</table>
</form>
<form action='http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit'
method="post" target="_blank">
<table>
<tr>
<td>Celsius to Fahrenheit:</td>
<td>
<input class="frmInput" type="text" size="4" name="Celsius">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="submit" value="Submit" class="button">
</td>
</tr>
</table>
</form>
最佳答案
由于我无法发表评论,因此您提供的代码中需要更正一些内容:
在构建 SOAP 请求(“sr”变量)结束时,您可以将其连接起来。去掉+。
您还可以检查 xml.onreadystatechange 和您提供的函数(使用 ==)之间的相等性,而不是将该函数分配给该属性。只需将其更改为单个等号即可。
我没有立即看到任何其他会导致此失败的内容,但如果您想从控制台检查 XMLHttpRequest 对象,请将其设置为全局变量而不是本地(函数范围)变量。我猜你的计划是通过 Firebug 中的网络检查器查看响应,但自从我使用它以来已经很长时间了,所以我不记得这是否可能,但我想我应该包含代码最后在控制台中手动查看该对象。
开头标有减号的行将被删除/更改,标有加号的行将被添加。
<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript">
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://192.168.0.251:9080/wsa/wsa1/wsdl?targetURI=urn:services-progress-com:Agrosys:Agroserver', true);
// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:services-progress-com:Agrosys:Agroserver:AgroEstagio"> ' +
'<soapenv:Header/> ' +
'<soapenv:Body> ' +
'<urn:lnestagio> ' +
'<urn:vvalor>5</urn:vvalor> ' +
'</urn:lnestagio> ' +
'</soapenv:Body> ' +
- '</soapenv:Envelope> ' +
+ '</soapenv:Envelope> ';
- xmlhttp.onreadystatechange == function () {
+ xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert('done use firebug to see response');
}
}
};
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
+ window.xmlhttp = xmlhttp;
}
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" value="Soap" onclick="soap();" />
</div>
</form>
</body>
<html>
关于javascript - 如何简单地让 HTML 发送一个号码并接收一个号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28591273/