首先,这么用是不好的。最好用ashx,但也难免遇到这种需求。开发过这么一个系统,每天访问量最多100,web服务器压力很小,完全大马拉小车,主要压力都在数据库服务器上,要做大量的统计。所以页面直接全上服务器控件搞定。用到ajax的时候也懒得再写个ashx了,直接aspx里写了。下面是例子:
前端:
function AjaxRquest() { $.ajax({ url: location.href, type: "POST", data: { "RequestType": "AjaxRequest", "id": "1" },//模拟个数据 success: function(data) { alert(data); } }); }
后台:
protected void Page_Load(object sender, EventArgs e) { if (Request["RequestType"] == "AjaxRequest") { string id = Request["id"]; Response.Clear(); Response.Write("ID : " + id + " ," + DateTime.Now); Response.End(); return; } }