Jquery ajax傳遞復(fù)雜參數(shù)給WebService的實(shí)現(xiàn)代碼
更新時(shí)間:2011年08月08日 23:56:21 作者:
Jquery ajax傳遞復(fù)雜參數(shù)給WebService的實(shí)現(xiàn)代碼,需要的朋友可以參考下。主要是屬性比較多。
Entity:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace Entity
{
[DataContract]
public class User
{
[DataMember]
public string Name
{
get;
set;
}
[DataMember]
public int Age
{
get;
set;
}
}
}
WebService:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Entity;
namespace JQuery.Handler
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class UserService1 : System.Web.Services.WebService
{
[WebMethod]
public string ComplexType(User hero,List<User> users)
{
return hero.Name + " has " + users.Count + " people!";
}
}
}
Html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ajax</title>
<script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btnWeb").click(function () {
$.ajax(
{
type: "post",
url: "../Handler/UserService.asmx/ComplexType",
dataType:"json",
contentType:"application/json",
data: '{"hero": {"Name":"zhoulq","Age":27},"users":[{"Name":"zhangs","Age":22},{"Name":"wangw","Age":26},{"Name":"liuj","Age":25},
{"Name":"luos","Age":24}]}',
success: function (data) { $("#web").text(data.d); }
});
});
});
</script>
</head>
<body>
<input id="btnWeb" type="button" value="請(qǐng)求WebService" /><label id="web"></label>
</body>
</html>
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace Entity
{
[DataContract]
public class User
{
[DataMember]
public string Name
{
get;
set;
}
[DataMember]
public int Age
{
get;
set;
}
}
}
WebService:
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Entity;
namespace JQuery.Handler
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class UserService1 : System.Web.Services.WebService
{
[WebMethod]
public string ComplexType(User hero,List<User> users)
{
return hero.Name + " has " + users.Count + " people!";
}
}
}
Html:
復(fù)制代碼 代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ajax</title>
<script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btnWeb").click(function () {
$.ajax(
{
type: "post",
url: "../Handler/UserService.asmx/ComplexType",
dataType:"json",
contentType:"application/json",
data: '{"hero": {"Name":"zhoulq","Age":27},"users":[{"Name":"zhangs","Age":22},{"Name":"wangw","Age":26},{"Name":"liuj","Age":25},
{"Name":"luos","Age":24}]}',
success: function (data) { $("#web").text(data.d); }
});
});
});
</script>
</head>
<body>
<input id="btnWeb" type="button" value="請(qǐng)求WebService" /><label id="web"></label>
</body>
</html>
您可能感興趣的文章:
- Jquery + Ajax調(diào)用webService實(shí)例代碼(asp.net)
- jQuery AJAX 調(diào)用WebService實(shí)現(xiàn)代碼
- 關(guān)于jquery ajax 調(diào)用帶參數(shù)的webservice返回XML數(shù)據(jù)一個(gè)小細(xì)節(jié)
- jQuery Ajax方法調(diào)用 Asp.Net WebService 的詳細(xì)實(shí)例代碼
- asp.net下使用jquery 的ajax+WebService+json 實(shí)現(xiàn)無(wú)刷新取后臺(tái)值的實(shí)現(xiàn)代碼
- Jquery Ajax學(xué)習(xí)實(shí)例6 向WebService發(fā)出請(qǐng)求,返回DataSet(XML) 異步調(diào)用
- Jquery Ajax學(xué)習(xí)實(shí)例3 向WebService發(fā)出請(qǐng)求,調(diào)用方法返回?cái)?shù)據(jù)
- Jquery Ajax學(xué)習(xí)實(shí)例4 向WebService發(fā)出請(qǐng)求,返回實(shí)體對(duì)象的異步調(diào)用
- Jquery Ajax學(xué)習(xí)實(shí)例5 向WebService發(fā)出請(qǐng)求,返回泛型集合數(shù)據(jù)的異步調(diào)用
- jQuery ajax調(diào)用webservice注意事項(xiàng)
相關(guān)文章
jquery彈窗插件colorbox綁定動(dòng)態(tài)生成元素的方法
這篇文章主要介紹了jquery彈窗插件colorbox綁定動(dòng)態(tài)生成元素的方法,colorbox是一款非常好用的彈窗插件,需要的朋友可以參考下2014-06-06用jQuery實(shí)現(xiàn)可輸入多選下拉組合框?qū)嵗a
這篇文章主要介紹了用jquery實(shí)現(xiàn)可輸入多選下拉組合框的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2017-01-01用JQuery調(diào)用Session的實(shí)現(xiàn)代碼
用JQuery調(diào)用Session的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-10-10webpack寫(xiě)jquery插件的環(huán)境配置
本篇文章給大家講述了用webpack開(kāi)發(fā)jquery插件需要的環(huán)境以及配置講解,有需要的讀者們參考下吧。2017-12-12用jquery實(shí)現(xiàn)點(diǎn)擊欄目背景色改變
用jquery如何實(shí)現(xiàn)點(diǎn)擊一欄目實(shí)現(xiàn)欄目變色,再點(diǎn)擊另一欄目也變色,但原來(lái)的變回原色,本文提供解決方法,需要了解的朋友可以參考下2012-12-12jQuery實(shí)現(xiàn)表格元素動(dòng)態(tài)創(chuàng)建功能
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)表格元素動(dòng)態(tài)創(chuàng)建功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01