如何使用JavaScript创建带有SOAP消息的请求
How to create request with SOAP message with JavaScript?
我有一个Web服务,我想调用一些方法。为此,我创建了:
<html>
<head>
<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://localhost:8080/services/StockQuoteService/";
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 xmlns:m="http://sample/">'+
' <m:getPrice>'+
' <m:symbol>IBM</m:symbol>'+
' </m:getPrice>'+
'</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")
$("#response").text($(req.responseXML).find("HelloResult").text());
}
function processError(data, status, req) {
alert(req.responseText + " " + status);
}
</script>
</head>
<body>
<input id="btnCallWebService" value="Call web service" type="button" />
<div id="response" />
</body>
</html>
但每次出现错误parseerror
时,都会出现"无法读取null的属性'documentElement'"。但当我从谷歌Chrome应用程序调用我的服务"邮差"时,我没有出错。如何使用Java脚本创建对Web服务的SOAP请求?
这只适用于IE。
<script language="JavaScript">
var request = new XMLHttpRequest();
request.open('POST', 'http://www.webserviceX.NET//CurrencyConvertor.asmx',true);
var m_request = '<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><ConversionRate xmlns="http://www.webserviceX.NET/"><FromCurrency>INR</FromCurrency><ToCurrency>USD</ToCurrency> </ConversionRate> </soap:Body></soap:Envelope>'
request.setRequestHeader('Content-Type', 'text/xml');
request.send(m_request);
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
alert("VALUE" + request.responseText);
}
}
</script>
相关文章:
- Ajax聊天消息重复而不仅仅是更新
- 如果localstorage为空,则显示欢迎消息
- 使用带有JavaScript的SOAP WebService
- 绑定时将Parsley minlength消息作为选项传递时,未对其进行自定义
- 离开页面时弹出消息
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- 消息显示之外的淘汰验证
- 选项卡侦听器未被来自后台脚本的消息激活
- jQuery在输入下验证post错误消息
- Scipt未在选定选项卡中执行以发送和接收消息
- 检查xmlhttprequest问题的消息
- AngularJs对ng消息的自定义替换
- ng消息仅在触摸时显示错误,并在错误的初始显示上转换
- 当用户按下回车键时,自动在text区域/text中插入消息
- 如果消息框答案为YES,则用Javascript填写表单
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- 解析云代码错误:解析.错误{代码:141,消息:“未调用成功/错误”}
- Node.js上的WebSocket,并在所有连接的客户端之间共享消息
- 如何使用JavaScript创建带有SOAP消息的请求
- Web服务——如何使用javascript创建用于文件上传的soap消息