ajax请求aspx页面

  首先,这么用是不好的。最好用ashx,但也难免遇到这种需求。开发过这么一个系统,每天访问量最多100,web服务器压力很小,完全大马拉小车,主要压力都在数据库服务器上,要做大量的统计。所以页面直接全上服务器控件搞定。用到ajax的时候也懒得再写个ashx了,直接aspx里写了。下面是例子:

  前端:

 1         function AjaxRquest() {
 2             $.ajax({
 3                 url: location.href,
 4                 type: "POST",
 5                 data: { "RequestType": "AjaxRequest", "id": "1" },//模拟个数据
 6                 success: function(data) {
 7                     alert(data);
 8                 }
 9             });
10         }

  后台:

 1     protected void Page_Load(object sender, EventArgs e)
 2     {
 3         if (Request["RequestType"] == "AjaxRequest")
 4         {
 5             string id = Request["id"];
 6             Response.Clear();
 7             Response.Write("ID : " + id + " ," + DateTime.Now);
 8             Response.End();
 9             return;
10         }
11     }

 

posted @ 2014-08-04 16:29  David Huang  阅读(4710)  评论(2编辑  收藏  举报