jQuery MiniUI

标题: ashx文件执行 [打印本页]

作者: davis3747    时间: 2017-1-12 15:16:53     标题: ashx文件执行


  1. 前端代码
  2. <div id="GetMenu" class="mini-datagrid" style="width: 100%;" url="/Ashx/SysMenu/test.aspx?method=GetMenuList" idfield="id">
  3.                     <div property="columns">
  4.                         <div field="Menu_Name" width="60" headeralign="center" allowsort="true">菜单名称</div>
  5.                         <div field="Menu_Img" width="15" allowsort="true" renderer="onGenderRenderer" align="center" headeralign="center">图标</div>
  6.                         <div field="Menu_Type" width="15" allowsort="true" headeralign="center">类型</div>
  7.                         <div field="birthday" width="25" headeralign="center" allowsort="true">连接目标</div>
  8.                         <div field="educational" width="25" headeralign="center">显示顺序</div>
  9.                         <div field="NavigateUrl" width="200" headeralign="center">连接地址</div>
  10.                     </div>
  11.                 </div>
复制代码
ashx代码   开始以为自己写的有问题,直接把DEMO的搬过来还是不执行
  1. public void ProcessRequest(HttpContext context)
  2.         {
  3.             context.Response.ContentType = "text/plain";
  4.             String name = context.Request["name"];
  5.             String methodName = context.Request["method"];
  6.             Type type = this.GetType();
  7.             MethodInfo method = type.GetMethod(methodName);
  8.             
  9.             if (method == null) throw new Exception("method is null");
  10.             try
  11.             {
  12.                 method.Invoke(this, null);
  13.             }
  14.             catch (Exception ex)
  15.             {
  16.                 Hashtable result = new Hashtable();
  17.                 result["error"] = -1;
  18.                 result["message"] = ex.Message;
  19.                 result["stackTrace"] = ex.StackTrace;
  20.                 String json = JSON.Encode(result);
  21.                 Response.Clear();
  22.                 Response.Write(json);
  23.             }

  24.         }
  25.         Base_SystemBLL sysbll = new Base_SystemBLL();
  26.         public void GetMenuList()
  27.         {
  28.             String id = Request["id"];
  29.             Hashtable result = sysbll.GetMenuList();
  30.             String json = JSON.Encode(result);
  31.             Response.Write(json);
  32.         }
复制代码
替换成aspx执行没有问题,直接显示数据了。但是ASHX怎么整都不现实数据
下面是aspx页面代码可以正常显示数据
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             String methodName = Request["method"];
  4.             Type type = this.GetType();
  5.             MethodInfo method = type.GetMethod(methodName);
  6.             if (method == null) throw new Exception("method is null");

  7.             try
  8.             {
  9.                 method.Invoke(this, null);
  10.             }
  11.             catch (Exception ex)
  12.             {
  13.                 Hashtable result = new Hashtable();
  14.                 result["error"] = -1;
  15.                 result["message"] = ex.Message;
  16.                 result["stackTrace"] = ex.StackTrace;
  17.                 String json = JSON.Encode(result);
  18.                 Response.Clear();
  19.                 Response.Write(json);
  20.             }
  21.         }

  22.         Base_SystemBLL sysbll = new Base_SystemBLL();
  23.         public void GetMenuList()
  24.         {
  25.             String id = Request["id"];
  26.             Hashtable result = sysbll.GetMenuList();
  27.             String json = JSON.Encode(result);
  28.             Response.Write(json);
  29.         }
复制代码
老大 帮看看那里有错。还是我的写法不对



作者: dforce    时间: 2017-1-12 15:42:39

打开浏览器工具,检查你ashx页面时后台返回的到底是什么,应该是返回的数据不对了
像chrome,ie10+自动的f12都可以看
作者: davis3747    时间: 2017-1-12 16:14:01

同样的代码.只是一个ASPX另一个ashx来做数据提供服务
怎么会返回的格式不同.
崩溃
作者: dforce    时间: 2017-1-12 16:42:23

davis3747 发表于 2017-1-12 16:14
同样的代码.只是一个ASPX另一个ashx来做数据提供服务
怎么会返回的格式不同.
崩溃 ...

肯定是返回的内容不对了,不只是格式的问题,你可以用浏览器的交互看具体的返回信息
作者: davis3747    时间: 2017-1-12 17:04:10

dforce 发表于 2017-1-12 16:42
肯定是返回的内容不对了,不只是格式的问题,你可以用浏览器的交互看具体的返回信息 ...

感谢版主.找到问题了.是返回数据格式问题.




欢迎光临 jQuery MiniUI (http://miniui.com/discuss/) Powered by Discuz! X2