我想从javascript调用服务,然后在html文件中显示响应数据。可能吗?有人做过吗?任何指示或解决方案都将有所帮助。谢谢
请求消息:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:log="http://login">
<soapenv:Header/>
<soapenv:Body>
<log:validateLogin>
<log:login>
<log:password>password</log:password>
<log:username>username</log:username>
</log:login>
</log:validateLogin>
</soapenv:Body>
</soapenv:Envelope>
回应讯息:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<validateLoginResponse xmlns="http://login">
<validateLoginReturn>true</validateLoginReturn>
</validateLoginResponse>
</soapenv:Body>
</soapenv:Envelope>
我需要创建请求消息,将其发送到服务,并读取响应。
最佳答案
你可以试试
var id=1;
$.ajax({
type: 'post',
url: '../webservice.asmx/yourmethod',
contentType: "application/json; charset=utf-8",
data:{'id':id}
dataType: "json",
beforeSend: function () {
//show wait
},
success: function (msg) {
if (msg.d != null) {
//result is obtained
}
}
});