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

jquery $.getJSON 与.NET 结合用法推荐

废话不多说,给出文件先:

Handler.ashx

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

using ?System;
using ?System.Web;
using ?System.Data;
using ?System.Text;
public ? class ?Handler?:?IHttpHandler?{
????
????
public ? void ?ProcessRequest?(HttpContext?context)?{
????????
/* context.Response.ContentType?=?"text/plain";
????????string?data?=?"[{name:\"fan\",age:26},{name:\"wang\",age:25}]";//构建的json数据
????????context.Response.Write(data);
*/

????????DataSet?ds?
= ? new ?DataSet();
????????DataTable?dt?
= ? new ?DataTable();
????????dt.Columns.Add(
" name " ,? typeof ( string ));
????????dt.Columns.Add(
" year " ,? typeof ( string ));
????????dt.Columns.Add(
" avg " ,? typeof ( string ));
????????DataRow?tr?
= ?dt.NewRow();
????????tr[
" name " ]? = ? " 张三<