ASP.NET中Ajax的用法

  在ASP.NET中应用Ajax的格式如下:

前台代码(用JQuery库)

 

 1 $.ajax({
 2 
 3   type: "POST",
 4 
 5   async: true,
 6 
 7   url: "../Ajax/ajax.ashx",
 8 
 9   dataType: "html",
10 
11   data: "uid=123"
12 
13   success: function (result)
14   {
15       //do successful sth
16   },
17 
18   error: function (XMLHttpRequest, textStaus, errThrown)
19   {
20       //do error sth
21   }
22 
23 })

 

Ajax(一般性处理程序)中代码如下:

1 public void ProcessRequest (HttpContext context) 
2 {
3     context.Response.ContentType = "text/plain";
4     string uid = context.Request.Params["uid"].ToString();
5     string result = "Hello World";
6     context.Response.Write(result);
7 }

 

posted @ 2016-07-11 15:37  A&B  阅读(462)  评论(0编辑  收藏  举报