ASP.NET—009:前台传值的另一种方式$.post

前台给后台传值,前面用的是$.ajax,还有另一种方式,当然也是ajax方法,那就是$.post。
用法也很简单,直接看例子:
前台
<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();
        }
    }

效果


代码下载 http://download.csdn.net/detail/yysyangyangyangshan/7132213 
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页