微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

起步X5开发HTML5通过ajax调用WebService服务,调用的两种方式SOAP和Result

使用JS调用webservce都可以参考

1.ajax调用soap方式的WebService


var wsUrl = 'http://192.168.1.103:9080/bdposback/webServicesPOS/cxfssh.ws';

// 请求体
var soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wss="http://wsservice.bdznxt.com/"><soapenv:Header/><soapenv:Body><wss:testString><arg0>aaa</arg0></wss:testString></soapenv:Body></soapenv:Envelope>';
var json;
$.ajax({
"url" : wsUrl,
"type" : 'POST',
"async" : false,
"dataType" : 'xml',
"Content-Type" : 'text/xml;charset=UTF-8',
"data" : soap,
"success" : function(data) {
// alert('OK!');
var o = $(data);
// alert(o.find('return').eq(0).text());
json=$.parseJSON(o.find('return').eq(0).text());
alert(json.istelnet+':'+json.telnetMsg);
},
"error" : function() {
alert('error!');
}
});


2.ajax调用Result方式的WebService

var wsUrlRESULT = 'http://192.168.1.103:9080/bdposback/webServicesPOS/restBase/addUser2'; var jsonStr = ''; $.ajax({ "type" : 'POST',"async" : false,"dataType" : 'json',"ContentType" : 'application/json',"data" : JSON.stringify('{"name": "acb"}'),"url" : wsUrlRESULT,"success" : function(data) { jsonStr = data; alert('OK!'); //alert(o.find('return').eq(0).text()); //json=$.parseJSON(o.find('return').eq(0).text()); //alert(json.istelnet); },"error" : function() { alert('error!'); } });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。