起步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!'); } });

相关文章

HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码