AJAX一般处理程序

时间:2023-02-21 21:06:50
 1 <script type= " text/javascript ">
 2 function Tpfb(wzfbID) {
 3 $.messager.confirm( " 系统提示 "" 您确定要发布吗? ", function (r) {
 4  if (r) {
 5 $.ajax({
 6 cache: false,
 7 type:  " GET ",
 8 url:  ' TP_WZFB.ashx?HandlerType=WZFB&FBWZID= ' + wzfbID +  ' &TITLE= ' + 
 9 
10 $( " #txtTitle ").val(),
11 dataType:  ' json ',
12 success: function(data)
13 {
14  if (data.State ==  " 1 ")
15 {
16 $.messager.alert( " 系统提示 "" 发布成功! ");
17 parent.location.href = parent.location.href;
18 }
19  else
20 $.messager.alert( " 系统提示 ", data.Message,  " error ");
21 }
22 });
23 }
24 });
25 }
26 </script>
27 
28  
29 
30  2、.ashx(一般处理程序文件)的参数接收和处理方法:
31 
32  // 接收
33 
34  public  override  void OnRequest(HttpContext context)
35 {
36 context.Response.ContentType =  " text/plain ";
37  string strContext =  "";
38  string HandlerType = context.Request[ " HandlerType "];
39  switch (HandlerType)
40 {
41  case  " WZFB ":
42 strContext = Tpfb(context);
43  break;
44  default:
45  break;
46 }
47 context.Response.Write(strContext);
48 }
49 
50  // 处理方法
51 
52  private  string Tpfb(HttpContext context)
53 {
54  // 投票信息ID
55  string fbwzID = context.Request[ " FBWZID "];
56 
57  return Hzjg.GlobalExpand.ToJson(oMes); // 结果要返回JSON格式字符串,与前台调用
58 
59 AJAX保持一致
60 
61 }