用法也很简单,直接看例子:
前台
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="btnFirst" runat="server" Text="按钮1"/> </form> </body> <script type="text/javascript" src="/Scripts/Ajax.js"></script> <script type="text/javascript" src="/Scripts/jquery-1.4.1.js"></script> <script language="javascript" type="text/javascript"> var handleUrl = window.location.href; $(document).ready(function () { $("#<%=btnFirst.ClientID%>").bind("click", function () { FunctionFirst(); return false; }); }); function FunctionFirst() { $.post(handleUrl,{Operate:"Click",Pdata:JSON.stringify(GetData())},function(result) { }); return false; } function GetData(){ var arrayData = new Array(); var obj = new Object(); obj.objID="1000"; obj.objValue = "TestData"; arrayData.push(obj); return arrayData; } </script> </html>后台接收
public partial class ChildFrm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { switch (Request["Operate"]) { case "Click": GetPageData(); break; default: break; } } private void GetPageData() { string strJson = Request["Pdata"].ToString(); } }
效果