日期:2014-05-16  浏览次数:20655 次

$.post参数在一般处理程序中接收问题
无法再一般 处理程序中接收到参数action,在这里把所有代码发出,是因为在asp.net版本没的到解决,所以发全部代码,大哥大姐们帮忙啊,谢谢
前台代码:
HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title></title>
   <script src="js/jquery-1.4.2-vsdoc.js" type="text/javascript"></script>
   <script src="js/jquery-1.4.2.js" type="text/javascript"></script>
   <script type="text/javascript">
     
    
  $(function () {
   $.post("WSXFY.ashx", {"action":"getpagecount" }, function (data, status) {
   for (var i = 1; i <= data; i++) {
   var td = $("<td><a href=''>" + i + "</a></td>");
   $("#trPage").append(td);
   }
   });   
  });
   $("#trPage td").click(function (e) {
   e.preventDefault();
   $.post("WSXFY.ashx", { "action": "getpagedata", "pagenum": $(this).text() },
   function (data, staus) {
   var comments = $.parseJSON(data);
   $("#ulComment").empty();
   for (var i = 0; i < comments.length; i++) {
   var comment = comments[i];
   var li = "<li>" + comment.id + comment.name + comment.Development + comment.Note + comment.Datetime + "</li>";
   $("#ulComment").append(li);
   }
   });
   });   
    
  </script>
</head>
<body>
<div >
<ul id="ulComment">


</ul>
<table>
<tr ></tr>

</table>
</div>
</body>
</html>


后台代码:
C# code

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Script.Serialization;
using System.Collections.Generic;

public class Handler : IHttpHandler {
     
  public void ProcessRequest (HttpContext context) {
   context.Response.ContentType = "text/plain";
   // string action=context.Request["action"];//无法获取action的值
   //string action=context.Request.Form["action"];
   // string action=context.Request.QueryString["action"];
   string action = context.Request.Params["action"];
   // string action = "getpagedata";
   string pagenum = context.Request["pagenum"];//无法获取pagenum的值
   //string pagenum = "1";
     
  int pagecount;//总页数
   if (action == "getpagecount")
   {
   string cmdString = @"select count(*) from Table1";
   using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
   {
   using(SqlCommand cmd = new SqlCommand(cmdString, conn))
   {
   conn.Open();
   int count =Convert.ToInt32(cmd.ExecuteScalar());
   pagecount = count/10;
   }
     
  }
   if (pagecount % 10 == 0)
   {
   pagecount++;
   }
   context.Response.Write(pagecount);
   }
   else if (action == "getpagedata")
   {
   string cmdString = @"select * from (select id ,name,Development,Note,Datetime,Row_Number()over(order by id) as rownum from table1)t where t.rownum>=@pagenum*10-9 and t.rownum<=@pagenum*10";
   using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
   {
   using (SqlCommand cmd = new SqlCommand(cmdString, conn))
   {
   conn.Open();
   cmd.Parameters.Add("@pagenum",pagenum);
   SqlDataAdapter da = new SqlDataAdapter(cmd);
   DataSet ds = new DataSet();
   da.Fill(ds);
     
    
  List<comment> list = new List<c