庹庹

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1.new httphandler:

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

using System;
using System.Web;

public class AjaxHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType
= "text/plain";

System.Collections.Generic.List
<System.Collections.Generic.Dictionary<string, string>> parent = new GucDataFetchEntLib.GucAddressingDao().GetDataCenter();
System.Web.Script.Serialization.JavaScriptSerializer js
= new System.Web.Script.Serialization.JavaScriptSerializer();

context.Response.Write(js.Serialize(parent));
}

public bool IsReusable
{
get
{
return false;
}
}

}

2.call httphandler in page 

function ajaxPageMethod() {
$.ajax({
type:
"GET",
contentType:
"application/json",
url:
"AjaxHandler.ashx",
success: function (list) {
alert(list);
$(
"#result").html(list);
},
error: function (xhr) {
$(
"#result").html("request wcf sever error!");
}
});
}

posted on 2011-05-27 16:38  庹林  阅读(379)  评论(0编辑  收藏  举报