前台JavaScript <script src="../js/jquery-1.5.1.min.js" type="text/javascript"></script> <script type="text/javascript" language="javascript"> function TT() { var txtpost=document.getElementById("Text1").value; $.get("Default.aspx", { Action:"action", name: "John", time: "2pm" }, function(data){ //此處是回調函數 接收從背景傳回的值 alert(data); //接回來的值是一串字元串 }); } </script> C# 背景方法 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ajax(); } } private void ajax() { string action = Request["Action"]; //最得前台的JS的第一個參數 if (!string.IsNullOrEmpty(action) && action == "action") //判斷是否通過前台的點選事件進來的 { Response.Write("你從前台JS裡傳入的是:" + Request["name"].ToString() + "和" + Request["time"].ToString()); Response.End(); } } |
補充啊:以下2句是相等的
1、