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="請求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="請求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)無刷新取后臺值的實(shí)現(xiàn)代碼
- Jquery Ajax學(xué)習(xí)實(shí)例6 向WebService發(fā)出請求,返回DataSet(XML) 異步調(diào)用
- Jquery Ajax學(xué)習(xí)實(shí)例3 向WebService發(fā)出請求,調(diào)用方法返回?cái)?shù)據(jù)
- Jquery Ajax學(xué)習(xí)實(shí)例4 向WebService發(fā)出請求,返回實(shí)體對象的異步調(diào)用
- Jquery Ajax學(xué)習(xí)實(shí)例5 向WebService發(fā)出請求,返回泛型集合數(shù)據(jù)的異步調(diào)用
- jQuery ajax調(diào)用webservice注意事項(xiàng)
相關(guān)文章
jQuery實(shí)現(xiàn)當(dāng)按下回車鍵時(shí)綁定點(diǎn)擊事件
當(dāng)按下回車鍵時(shí),綁定按鈕點(diǎn)擊事件,本文為大家介紹下jQuery回車鍵綁定點(diǎn)擊事件的具體實(shí)現(xiàn)2014-01-01
基于input動(dòng)態(tài)模糊查詢的實(shí)現(xiàn)方法
下面小編就為大家分享一篇基于input動(dòng)態(tài)模糊查詢的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
jQuery實(shí)現(xiàn)菜單的顯示和隱藏功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)菜單的顯示和隱藏功能,結(jié)合實(shí)例形式分析了jQuery基于事件響應(yīng)及css方法動(dòng)態(tài)改變菜單樣式的相關(guān)操作技巧,需要的朋友可以參考下2018-07-07
jquery實(shí)現(xiàn)點(diǎn)擊頁面計(jì)算點(diǎn)擊次數(shù)
這篇文章主要給大家分享了一段使用jquery實(shí)現(xiàn)點(diǎn)擊頁面計(jì)算點(diǎn)擊次數(shù)的代碼,非常實(shí)用,有需要的小伙伴參考下。2015-01-01

