基于JQuery的訪問WebService的代碼(可訪問Java[Xfire])
$(function () {
$("#btnWs").click(btnAjaxPost);
});
function btnAjaxPost(event) {
$.ajax({
type: "POST",
contentType:"text/xml",
url:"http://*****/WebServiceTest/services/HelloWorldService",
data:getPostData(),//這里不該用JSON格式
dataType:'xml',//這里設(shè)成XML或者不設(shè)。設(shè)成JSON格式會(huì)讓返回值變成NULL
success: function(xml) {
//對(duì)結(jié)果做XML解析。
//瀏覽器判斷 (IE和非IE完全不同)
if($.browser.msie){
$("#result").append(xml.getElementsByTagName("ns1:out")[0].childNodes[0].nodeValue+"<br/>");
}
else{
$(xml).find("out").each(function(){
$("#result").append($(this).text()+"<br/>");
})
}
},
error: function(x, e) {
alert('error:'+x.responseText);
},
complete: function(x) {
//alert('complete:'+x.responseText);
}
});
}
//定義滿足SOAP協(xié)議的參數(shù)。
function getPostData()
{
//根據(jù)WSDL分析sayHelloWorld是方法名,parameters是傳入?yún)?shù)名
var postdata="<?xml version=\"1.0\" encoding=\"utf-8\"?>";
postdata+="<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/\">";
postdata+="<soap:Body><sayHelloWorld xmlns=\"http://tempuri.org/\">";
postdata+="<parameters>"+$("#txtName").val()+"</parameters>";
postdata+="</sayHelloWorld></soap:Body>";
postdata+="</soap:Envelope>";
return postdata;
}
完整例子SVN地址:http://theyounglearningmaterials.googlecode.com/svn/trunk/JavaWebServices/WebServiceTest/
我以后所有學(xué)習(xí)的例子都會(huì)放在 http://theyounglearningmaterials.googlecode.com/svn/trunk/里面,方便管理防止丟失。
相關(guān)文章
jQuery使用attr()方法同時(shí)設(shè)置多個(gè)屬性值用法實(shí)例
這篇文章主要介紹了jQuery使用attr()方法同時(shí)設(shè)置多個(gè)屬性值的用法,實(shí)例分析了jQuery中attr方法實(shí)現(xiàn)多個(gè)屬性設(shè)置的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03jQuery 獲取跨域XML(RSS)數(shù)據(jù)的相關(guān)總結(jié)分析
下面小編就為大家?guī)硪黄猨Query 獲取跨域XML(RSS)數(shù)據(jù)的相關(guān)總結(jié)分析。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05DIV隨滾動(dòng)條滾動(dòng)而滾動(dòng)的實(shí)現(xiàn)代碼【推薦】
下面小編就為大家?guī)硪黄狣IV隨滾動(dòng)條滾動(dòng)而滾動(dòng)實(shí)現(xiàn)代碼【推薦】。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-04-04Spring MVC中Ajax實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)的簡單實(shí)例
下面小編就為大家?guī)硪黄猄pring MVC中Ajax實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07jQuery根據(jù)ID獲取input、checkbox、radio、select的示例
獲取input、checkbox、radio、select的方法有很多,下面本例為大家介紹下根據(jù)ID來獲取2014-08-08基于jQuery實(shí)現(xiàn)掛號(hào)平臺(tái)首頁源碼
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)掛號(hào)平臺(tái)首頁源碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01jquery Tab 選項(xiàng)卡通用函數(shù)
用類作為選擇符雖然效率低點(diǎn)但是 可以多次重用 這個(gè)性質(zhì)不錯(cuò)2010-04-04基于jquery的文本框與autocomplete結(jié)合使用(asp.net+json)
基于jquery的文本框與autocomplete結(jié)合使用示例代碼,需要的朋友可以參考下2012-05-05