ajax + web service交互架构

用ajax结构直接与axis2提供的web service交互。

  • 环境要求

axis2 v1.4.1(eclipse v3.5的axis2插件只支持到该版本,别用1.5)

eclipse v3.5

 

  • 生成web服务

用eclipse新建"动态web项目",再新建你的web服务类,最后在右键点类名,菜单中选最下面的web service。按向导下去就成了。

注意首次用会提示要指定axis2的路径,从网上下个bin包,解开。然后再eclipse下的“首选项-axis2”中指定下目录。

 

 

public class Article { /** * 内容体获取关联信息 * @param contentId 关联体序号 * @return */ public ArticleInfo getContentInfoByConentId(long contentId){ System.out.println("contentId:"+contentId); ArticleInfo info = new ArticleInfo(); info.setBrowseTimes(1000); info.setCommentNum(20); info.setContentId(1); info.setTitle("测试标题"); MemberInfo author= new MemberInfo(); author.setNikeName("昵称"); info.setAuthor(author); List<ArticleComment> list= new ArrayList<ArticleComment>(); ArticleComment comment = new ArticleComment(); comment.setContent("匿名评论:)good!< img src='1.jpg' />"); comment.setAnonymity(true); comment.setCommenter("王一"); comment.setContentId(100); comment.setCommentId(1); list.add(comment); comment = new ArticleComment(); comment.setContent("署名评论:)good!<img src="2.jpg" mce_src="2.jpg" />"); comment.setAnonymity(false); comment.setCommenter("张三"); comment.setContentId(100); comment.setCommentId(2); list.add(comment); info.setComments(list); info.setScores(new int[]{1,2,3}); return info; } /** * 获取单篇内容体评论 * @param contentId * @return */ public List<ArticleComment> getComments(long contentId){ System.out.println("contentId:"+contentId); List<ArticleComment> list=new ArrayList<ArticleComment>(); ArticleComment comment = new ArticleComment(); comment.setContent("匿名评论:)good!<img src="1.jpg" mce_src="1.jpg" />"); comment.setAnonymity(true); comment.setCommenter("王一"); comment.setContentId(100); comment.setCommentId(1); list.add(comment); comment = new ArticleComment(); comment.setContent("署名评论:)good!<img src="2.jpg" mce_src="2.jpg" />"); comment.setAnonymity(false); comment.setCommenter("张三"); comment.setContentId(100); comment.setCommentId(2); list.add(comment); return list; } /** * 添加评论 * @param contentId 内容 * @param commenter * @param isAnonymity * @param content * @param citation * @return */ public boolean addComment(long contentId,long commenter,boolean isAnonymity,String content,String citation){ System.out.println("contentId:"+contentId); System.out.println("commenter:"+commenter); System.out.println("isAnonymity:"+isAnonymity); System.out.println("content:"+content); System.out.println("citation:"+citation); return true; } } public class ArticleInfo { long contentId; String title; int commentNum; long browseTimes; int[] scores; public int[] getScores() { return scores; } public void setScores(int[] scores) { this.scores = scores; } List<ArticleComment> comments; MemberInfo author; MemberInfo supp; public MemberInfo getSupp() { return supp; } public void setSupp(MemberInfo supp) { this.supp = supp; } public List<ArticleComment> getComments() { return comments; } public void setComments(List<ArticleComment> comments) { this.comments = comments; } public MemberInfo getAuthor() { return author; } public void setAuthor(MemberInfo author) { this.author = author; } public long getContentId() { return contentId; } public void setContentId(long contentId) { this.contentId = contentId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getCommentNum() { return commentNum; } public void setCommentNum(int commentNum) { this.commentNum = commentNum; } public long getBrowseTimes() { return browseTimes; } public void setBrowseTimes(long browseTimes) { this.browseTimes = browseTimes; } } public class ArticleComment { long contentId; long commentId; String commenter; String content; boolean anonymity; public long getContentId() { return contentId; } public void setContentId(long contentId) { this.contentId = contentId; } public long getCommentId() { return commentId; } public void setCommentId(long commentId) { this.commentId = commentId; } public String getCommenter() { return commenter; } public void setCommenter(String commenter) { this.commenter = commenter; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public boolean isAnonymity() { return anonymity; } public void setAnonymity(boolean anonymity) { this.anonymity = anonymity; } } public class MemberInfo { private String nikeName; public String getNikeName() { return nikeName; } public void setNikeName(String nikeName) { this.nikeName = nikeName; } private String name; }

 

  • 客户端(IE)代码

ws2.js代码

/******************************************************************************/ var WS = { Version : '0.1.1', Author : 'whm', Revision : '2009-07-29T18:00:00-7:00', Other : 'using prototype1.6.1' }; /******************************************************************************/ var XML = { createDocumentQName : function(qname) { return XML.createDocument(qname.namespace,qname.value_of()); }, createDocument : function(namespace,nodename) { return Try.these( function() { var doc = new ActiveXObject('Msxml2.XMLDOM'); if (typeof nodename != 'undefined'){ var root = XML.createElementNS(doc, nodename, namespace); doc.documentElement = root; }; return doc; }, function() { var doc = new ActiveXObject('Microsoft.XMLDOM'); if (typeof nodename != 'undefined'){ var root = XML.createElementNS(doc, nodename, namespace); doc.documentElement = root; } return doc; }, function() { return document.implementation.createDocument( namespace, nodename, null); } ) || false; }, createElementNS : function(document,nodename,namespace) { var el = Try.these( function() { var el = null; if (namespace) { el = document.createNode(1,nodename,namespace); } else { el = document.createNode(1,nodename,""); } return el; }, function() { var el = null; if (namespace) { el = document.createElementNS(namespace,nodename); } else { el = document.createElement(nodename); } return el; } ) || false; return el; }, createElementQName : function(document,qname) { return XML.createElementNS(document,qname.value_of(),qname.namespace); }, createAttributeNS : function(document,nodename,namespace,value) { var attr = Try.these( function() { return document.createNode(2,nodename,namespace);}, function() { return document.createAttributeNS(namespace,nodename);} ) || false; attr.nodeValue = value; return attr; }, createAttributeQName : function(document,qname,value) { return XML.createAttributeNS(document,qname.value_of(),qname.namespace,value); }, createAttribute : function(document,nodename,value) { var attr = Try.these( function() { return document.createNode(2, nodename);}, function() { return document.createAttribute(nodename);} ) || false; attr.nodeValue = value; return attr; }, createText : function(document,value) { var node = Try.these( function() { return document.createTextNode(value); } ) || false; return node; }, createCDATA : function(document,value) { var node = Try.these( function() { return document.createCDATASection(value); } ) || false; return node; }, getElementsByQName : function(element, qname) { var nl = null; if(!element.getElementsByTagNameNS) { nl = new Array(); var nodes = element.getElementsByTagName(qname.value_of()); for (var n = 0; n < nodes.length; n++) { if (nodes[n].namespaceURI == qname.namespace) { nl.push(nodes[n]); } } } else { nl = element.getElementsByTagNameNS(qname.namespace,qname.localpart); } return nl; }, load : function(url) { // Create a new document with the previously defined function var xmldoc = this.createDocument(); xmldoc.async = false; // We want to load synchronously xmldoc.load(url); // Load and parse return xmldoc; // Return the document }, transform : function(xmldoc, stylesheet, element) { var transformer = new XML.Transformer(stylesheet); transformer.transform(xmldoc, element); } }; XML.Transformer = function(stylesheet) { // Load the stylesheet if necessary. if (typeof stylesheet == "string"){ stylesheet = XML.load(stylesheet); } this.stylesheet = stylesheet; // In Mozilla-based browsers, create an XSLTProcessor object and // tell it about the stylesheet. if (typeof XSLTProcessor != "undefined") { this.processor = new XSLTProcessor( ); this.processor.importStylesheet(this.stylesheet); } }; XML.Transformer.prototype.transform = function(node, element) { // If element is specified by id, look it up. if (typeof element == "string") element = document.getElementById(element); if (this.processor) { // If we've created an XSLTProcessor (i.e., we're in Mozilla) use it. // Transform the node into a DOM DocumentFragment. var fragment = this.processor.transformToFragment(node, document); // Erase the existing content of element. element.innerHTML = ""; // And insert the transformed nodes. element.appendChild(fragment); } else if ("transformNode" in node) { // If the node has a transformNode( ) function (in IE), use that. // Note that transformNode( ) returns a string. element.innerHTML = node.transformNode(this.stylesheet); } else { // Otherwise, we're out of luck. throw "XSLT is not supported in this browser"; } }; /******************************************************************************/ WS.QName = Class.create({ initialize : function(localpart) { this.localpart = localpart; if (arguments[1]) this.namespace = arguments[1]; if (arguments[2]) this.prefix = arguments[2]; }, to_string : function() { return (this.namespace) ? '{' + this.namespace + '}' + this.localpart : this.localpart; }, value_of : function() { return ((this.prefix)?this.prefix + ':':'') + this.localpart; }, equals : function(obj) { return (obj instanceof WS.QName && obj.localpart == this.localpart && obj.namespace == this.namespace); } }); WS.QName.fromElement = function() { var qname = new WS.QName( (this.baseName)?this.baseName:this.localName, this.namespaceURI, this.prefix ); return qname; }; /******************************************************************************/ var SOAP = { Version : '1.1', URI : 'http://schemas.xmlsoap.org/soap/envelope/', XSI : 'http://www.w3.org/2000/10/XMLSchema-instance', XSIQNAME : new WS.QName( 'type', 'http://www.w3.org/2000/10/XMLSchema-instance','xsi'), XSINIL : new WS.QName( 'nil', 'http://www.w3.org/2000/10/XMLSchema-instance','xsi'), SOAPENCODING : 'http://schemas.xmlsoap.org/soap/encoding/', NOENCODING : null, ENCODINGSTYLE : new WS.QName( 'encodingStyle', 'http://schemas.xmlsoap.org/soap/envelope/','s') }; /******************************************************************************/ SOAP.Element = Class.create({ initialize : function() { if (arguments[0]) this.initialize_internal(arguments[0]); }, initialize_internal : function(element) { this.element = element; }, asElement : function() { return this.element; }, qname : function() { return WS.QName.fromElement.bind(this.element)(); }, set_encoding_style : function(style) { this.set_attribute(SOAP.ENCODINGSTYLE,style); }, declare_namespace : function(qname) { var ns = new WS.QName( qname.prefix, 'http://www.w3.org/2000/xmlns/', 'xmlns'); var value = (qname.namespace) ? qname.namespace : ''; var attr = XML.createAttributeQName( this.element.ownerDocument, ns, value ); if (this.element.setAttributeNodeNS) { this.element.setAttributeNodeNS(attr); } else { this.element.setAttributeNode(attr); } }, set_attribute : function(qname, value) { var attr = XML.createAttributeQName( this.element.ownerDocument, qname, value); if (this.element.setAttributeNodeNS) { this.element.setAttributeNodeNS(attr); } else { this.element.setAttributeNode(attr); } }, get_attribute : function(qname) { var val = null; for (var n = 0; n < this.element.attributes.length; n++) { var attr = this.element.attributes[n]; if (qname.equals(WS.QName.fromElement.bind(attr)())) { val = attr.nodeValue; break; } } return val; }, has_attribute : function(qname) { var val = null; for (var n = 0; n < this.element.attributes.length; n++) { var attr = this.element.attributes[n]; if (qname.equals(WS.QName.fromElement.bind(attr)())) { val = true; break; } } return val; }, clear_children : function() { var nodes = this.element.childNodes; for (var n = 0; n < nodes.length; n++) { this.element.removeChild(nodes[n]); } }, set_value : function(value, usecdata) { var doc = this.element.ownerDocument; // clear existing children this.clear_children(); if (usecdata) { this.element.appendChild(XML.createCDATA(doc,value)); } else { this.element.appendChild(XML.createText(doc,value)); } }, get_value : function() { return this.element.firstChild.nodeValue; }, add_child : function(element) { var doc = this.element.ownerDocument; if (element instanceof SOAP.Element) { this.element.appendChild(doc.importNode(element.element, true)); } else { this.element.appendChild(doc.importNode(element, true)); } }, create_child : function(qname) { var doc = this.element.ownerDocument; var el = XML.createElementQName(doc, qname); this.element.appendChild(el); var ret = new SOAP.Element(el); return ret; }, get_children : function(qname) { var nodes = XML.getElementsByQName(this.element,qname); var childnodes = new Array(); for (var n = 0; n < nodes.length; n++) { childnodes.push(new SOAP.Element(nodes[n])); } return childnodes; }, get_all_children : function() { var nodes = this.element.childNodes; var childnodes = new Array(); for (var n = 0; n < nodes.length; n++) { if (nodes[n].nodeType == 1) { childnodes.push(new SOAP.Element(nodes[n])); } } return childnodes; }, get_binder : function() { return WS.Binder.get_for_qname(this.qname()); } }); /******************************************************************************/ SOAP.Envelope = Class.create(SOAP.Element,{ initialize : function() { var element = arguments[0]; if (!element) { var document = XML.createDocumentQName(SOAP.Envelope.QNAME); element = document.documentElement; } this.initialize_internal(element); }, set_value : null, get_value : null, create_child : null, create_header : function() { if (!this.has_header()) { var doc = this.element.ownerDocument; var el = XML.createElementQName(doc, SOAP.Header.QNAME); if (this.element.firstChild) { this.element.insertBefore(el, this.element.firstChild); } else { this.element.appendChild(el); } var ret = new SOAP.Header(el); return ret; } else { return this.get_header(); } }, get_header : function() { var val = null; for (var n = 0; n < this.element.childNodes.length; n++) { if (this.element.childNodes[n].nodeType == 1) { var el = this.element.childNodes[n]; if (SOAP.Header.QNAME.equals(WS.QName.fromElement.bind(el)())) { val = new SOAP.Header(el); break; } } } return val; }, has_header : function() { var val = null; for (var n = 0; n < this.element.childNodes.length; n++) { if (this.element.childNodes[n].nodeType == 1) { var el = this.element.childNodes[n]; if (SOAP.Header.QNAME.equals(WS.QName.fromElement.bind(el)())) { val = true; break; } } } return val; }, create_body : function() { if (!this.has_body()) { var doc = this.element.ownerDocument; var el = XML.createElementQName(doc, SOAP.Body.QNAME); this.element.appendChild(el); var ret = new SOAP.Body(el); return ret; } else { return this.get_body(); } }, get_body : function() { var val = null; for (var n = 0; n < this.element.childNodes.length; n++) { if (this.element.childNodes[n].nodeType == 1) { var el = this.element.childNodes[n]; if (SOAP.Body.QNAME.equals(WS.QName.fromElement.bind(el)())) { val = new SOAP.Body(el); break; } } } return val; }, has_body : function() { var val = null; for (var n = 0; n < this.element.childNodes.length; n++) { if (this.element.childNodes[n].nodeType == 1) { var el = this.element.childNodes[n]; if (SOAP.Body.QNAME.equals(WS.QName.fromElement.bind(el)())) { val = true; break; } } } return val; } }); SOAP.Envelope.QNAME = new WS.QName('Envelope',SOAP.URI); /******************************************************************************/ SOAP.Header = Class.create(SOAP.Element,{ initialize : function(element) { this.initialize_internal(element); }, set_value : function() {}, get_value : function() {} }); SOAP.Header.QNAME = new WS.QName('Header',SOAP.URI); /******************************************************************************/ SOAP.Body = Class.create(SOAP.Element,{ initialize : function(element) { this.initialize_internal(element); }, set_value : function() {}, get_value : function() {}, set_rpc : function(method, params, encodingstyle) { var child = this.create_child(method); if (encodingstyle) { child.set_encoding_style(encodingstyle); } for (var n = 0; n < params.length; n++) { var param = params[n]; var pchild = null; if (param.name instanceof WS.QName) { pchild = child.create_child(param.name); } else { pchild = child.create_child( new WS.QName(param.name,method.namespace,method.prefix) ); } if (typeof param.value != "undefined" ) { if (typeof param.value == "boolean") //for boolean param.value = (param.value)?"true":"false"; pchild.set_value(param.value); } else { pchild.set_attribute(SOAP.XSINIL,'true'); } if (param.xsitype) { pchild.set_attribute(SOAP.XSIQNAME,param.xsitype.value_of()); } if (param.encodingstyle) { pchild.set_encoding_style(param.encodingstyle); } } } }); SOAP.Body.QNAME = new WS.QName('Body',SOAP.URI); /******************************************************************************/ WS.Handler = Class.create({ initialize : function() {}, on_request : function(call, envelope) {}, on_response : function(call, envelope) {}, on_error : function(call, envelope) {} }); /******************************************************************************/ WS.Binder = Class.create({ initialize : function() {}, to_soap_element : function(value_object,envelope) {}, to_value_object : function(soap_element) {} }); WS.Binder.register = function(qname,type,binder) { if (!WS.Binder.binders) WS.Binder.binders = new Array(); WS.Binder.binders.push({qname:qname,type:type,binder:binder}); }; WS.Binder.get_for_qname = function(qname) { if (!WS.Binder.binders) return null; var binder = null; for (var n = 0; n < this.binders.length; n++) { var b = this.binders[n]; if (b.qname.equals(qname)) { binder = b.binder; break; } } return binder; }; WS.Binder.get_for_type = function(type) { if (!WS.Binder.binders) return null; var binder = null; for (var n = 0; n < this.binders.length; n++) { var b = this.binders[n]; if (b.type == type) { binder = b.binder; break; } } return binder; }; /******************************************************************************/ WS.Call = Class.create({ initialize : function(uri) { this.uri = uri; this.handlers = new Array(); this.invokeHandlers = WS.Call.InvokeHandlers.bind(this.handlers); }, add_handler : function(handler) { this.handlers.push(handler); }, invoke_rpc : function(qname, params, encodingstyle, callback) { var env = new SOAP.Envelope(); env.create_body().set_rpc(qname,params,encodingstyle); this.invoke(env, callback); }, invoke : function(envelope, callback) { this.invokeHandlers(this,envelope,null,'request'); var call = this; var options = {}; options.postBody = envelope.asElement().ownerDocument; options.onComplete = function(transport) { try { var xml = transport.responseXML; if (xml) { var responseEnv = new SOAP.Envelope(xml.documentElement); call.invokeHandlers(call,responseEnv,transport, 'response'); callback(this, responseEnv, transport.responseText); } else { call.invokeHandlers(call,null,'error'); } } catch(e) { call.invokeHandlers(call,e,'error'); } }; options.requestHeaders = new Array(); options.requestHeaders.push('Content-Type'); //options.requestHeaders.push('application/xml'); options.requestHeaders.push('text/xml'); //兼容firefox if (this.soapAction) { options.requestHeaders.push('SOAPAction'); options.requestHeaders.push('"' + this.soapAction + '"'); } else { options.requestHeaders.push('SOAPAction'); options.requestHeaders.push('""'); } new Ajax.Request(this.uri,options); } }); WS.Call.InvokeHandlers = function(call, envelope, transport, state) { this.each( function(value) { switch(state) { case 'request': try { value.on_request(call,envelope, transport); } catch(e) {} break; case 'response': try { value.on_response(call,envelope, transport); } catch(e) {} break; case 'error': try { value.on_error(call,envelope,transport); } catch(e) {} break; } } ); }; /******************************************************************************/ var EnvelopeParser = Class.create({ initialize : function(envelope) { this.envelope = envelope; this.responseNode = envelope.get_body().get_all_children()[0]; if (this.responseNode.asElement().baseName == 'Fault' ){ //invoke fault this.succeed = false; }else{ this.succeed = true; }; }, isSucceed : function() { return this.succeed; }, getFaultObj : function(){ var obj = {}; this.responseNode.get_all_children().each(function(child){ eval('obj.'+child.asElement().baseName+'="'+child.asElement().nodeTypedValue+'"'); }); return obj; }, getReturn : function(){ var obj = this.paserEnveloper(this.responseNode); return obj["return"]; }, parseWithXSL: function(xsl,container){ XML.transform(this.envelope.asElement().parentNode,xsl,container); }, /** * node0 :return * parent : object */ paserEnveloper : function(n){ var p = {}; var stack = []; stack.push({node:n,parent:p}); while(stack.length>0){ var head=stack.pop(); head.node.get_all_children().each(function(child){ //has children var childName; if(Prototype.Browser.IE){ childName = child.asElement().baseName; }else{ childName = child.asElement().localName; } var childValue = {}; var ntmp = null; var ptmp ; if( !child.has_attribute(new WS.QName("type")) ){ //非对象 if(Prototype.Browser.IE){ childValue = child.asElement().nodeTypedValue; }else{ childValue = child.asElement().textContent; } }else{ ntmp = child; } if( typeof head.parent[childName] != 'undefined' ){ //complex type if ( head.parent[childName].constructor !== Array ){ var tmp = head.parent[childName]; head.parent[childName] = []; head.parent[childName].push(tmp); } var phead= head.parent[childName].push(childValue); ptmp = head.parent[childName][phead-1]; }else{ //simple type if ( child.get_attribute(new WS.QName("nil","http://www.w3.org/2001/XMLSchema-instance"))== "true" ) { //if null head.parent[childName] = null; }else{ head.parent[childName] = childValue; } ptmp = head.parent[childName]; } if ( ntmp != null){ stack.push({node:ntmp,parent:ptmp}); } }); } return p; } });

 

用法:

<html> <head> <mce:script type="text/javascript" src="js/prototype.js" mce_src="js/prototype.js"></mce:script> <mce:script type="text/javascript" src="js/ws2.js" mce_src="js/ws2.js"></mce:script> <mce:script type="text/javascript"><!-- function getContentInfoByConentId(conentId, container) { var call = new WS.Call('/myaxis2/services/Article'); var nsuri = 'http://members.lingtong.com'; var qn_op = new WS.QName('getContentInfoByConentId',nsuri); //var qn_op_resp = new WS.QName('sayHelloResponse',nsuri); call.invoke_rpc( qn_op, new Array( {name:'contentId',value:conentId} ),null, function(call,envelope) { $('soap').innerHTML = arguments[2].escapeHTML(); var evpobj = new EnvelopeParser(envelope); if ( evpobj.isSucceed() ){ var info = evpobj.getReturn(); ret = 'Invoke succeed !!!<br>'; //ret += '获取单节点id:'+returnNode.get_children(new WS.QName('contentId','http://po.members.lingtong.com/xsd'))[0].get_value()+'<br>'; ret += '<br>简单对象:'+info.contentId+"<br>"+info.title; ret += '<br>空对象:'+info.supp; }else{ ret = 'Invoke Error!!!'; var fault = evpobj.getFaultObj(); ret += '<br>原因:['+fault.faultcode+']'+fault.faultstring; } container.innerHTML = ret; } ); } function getComments(conentId, container) { var call = new WS.Call('/myaxis2/services/Article'); var nsuri = 'http://members.lingtong.com'; var qn_op = new WS.QName('getComments',nsuri); //var qn_op_resp = new WS.QName('sayHelloResponse',nsuri); call.invoke_rpc( qn_op, new Array( {name:'contentId',value:conentId} ),null, function(call,envelope) { $('soap').innerHTML = arguments[2].escapeHTML(); var evpobj = new EnvelopeParser(envelope); if ( evpobj.isSucceed() ){ ret = 'Invoke succeed !!!<br>'; var info = evpobj.getReturn(); evpobj.parseWithXSL("comments.xsl",container); }else{ ret = 'Invoke Error!!!'; var fault = evpobj.getFaultObj(); ret += '<br>原因:['+fault.faultcode+']'+fault.faultstring; container.innerHTML = ret; } } ); } function addComment(conentId, commenter, isAnonymity, content, citation, container) { var call = new WS.Call('/myaxis2/services/Article'); var nsuri = 'http://members.lingtong.com'; var qn_op = new WS.QName('addComment',nsuri); //var qn_op_resp = new WS.QName('sayHelloResponse',nsuri); call.invoke_rpc( qn_op, new Array( {name:'contentId',value:conentId}, {name:'commenter',value:commenter}, {name:'isAnonymity',value:isAnonymity, xsitype:new WS.QName('boolean','http://www.w3.org/2000/10/XMLSchema')}, {name:'content',value:content}, {name:'citation',value:citation} ),null, function(call,envelope) { $('soap').innerHTML = arguments[2].escapeHTML(); var evpobj = new EnvelopeParser(envelope); if ( evpobj.isSucceed() ){ var retvalue = evpobj.getReturnValue(); ret = 'Invoke succeed !!!<br>'; ret += '<br>结果:'+retvalue; }else{ ret = 'Invoke Error!!!'; var fault = evpobj.getFaultObj(); ret += '<br>原因:['+fault.faultcode+']'+fault.faultstring; } container.innerHTML = ret; } ); } // --></mce:script> <mce:style><!-- body { font-family: verdana; } #container { margin: 10pt; border: 1pt solid black; padding: 2pt; } #result { padding: 5pt; background-color: #eeeeee; } #soap { padding: 5pt; background-color: #eeeeee; font-size: 10pt; } --></mce:style><style mce_bogus="1">body { font-family: verdana; } #container { margin: 10pt; border: 1pt solid black; padding: 2pt; } #result { padding: 5pt; background-color: #eeeeee; } #soap { padding: 5pt; background-color: #eeeeee; font-size: 10pt; }</style> </head> <body> <input name="conentId" id="conentId" /> <input value="getContentInfoByConentId" type="button" onclick="getContentInfoByConentId($('conentId').value,$('result'))" /> <input value="getComments" type="button" onclick="getComments($('conentId').value,$('result'))" /> <br/> 评论内容: <textarea name="content" id="content" >

 

  • 参考

可参考以下文章。原文提供的js中有些问题,如不支持boolean型、XSL解析、prototype1.6.1等。

 

 

使用 Ajax 调用 SOAP Web 服务,第 1 部分 构建 Web 服务客户机.htm

http://www.ibm.com/developerworks/cn/webservices/ws-wsajax/

使用 Ajax 调用SOAP Web 服务,第 2 部分 扩展 Web 服务客户机.htm

http://www.ibm.com/developerworks/cn/webservices/ws-wsajax2/index.html

 

 

  • 与firefox兼容性

IE支持document.frames['xxx']、document.frames('xxx')

firefox支持frames['xxxx']

你可能感兴趣的:(ajax + web service交互架构)