ajax如何调用本页数据源不用一般处理程序
ajax如何调用本页数据源不用一般处理程序
摘自:http://www.cnblogs.com/LYunF/archive/2012/08/31/2665188.html
CS代码
View Code
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Services; public partial class TestAjax : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string methor = Request["act"]; if (!string.IsNullOrEmpty(methor)) { this.GetType().GetMethod(methor).Invoke(this, null); } } public void GetVal() { string val = "getVal 方法获取参数" + Request["arg"]; Response.Clear(); Response.Write(val); Response.End(); } }
页面代码
View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestAjax.aspx.cs" Inherits="TestAjax" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <script type="text/javascript" src="Js/jquery-1.8.1.min.js" language="javascript"></script> <script language="javascript" type="text/javascript"> function test() { var data = new Object(); data.act = "GetVal"; data.arg = "123"; $.post("TestAjax.aspx", data, function (data) { alert(data); }); } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="Button1" onclick="test()" type="button" value="测试ajax" /> </div> </form> </body> </html>