ajax 解决方案(Newtonsoft.Json +jQuery +ashx)

http://www.cnblogs.com/ie421/archive/2008/08/19/1271601.html

 

1.json :Newtonsoft.Json http://files.cnblogs.com/ie421/Json20.zip

2.js:jQuery  

3.服务器端:ashx

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

            string method = context.Request.Params["m"];

            if(method=="test")
                context.Response.Write(GetPersonListJosnString_2());
        }

    返回:{"ID":1,"FirstName":"肖","LastName":"永志"}

 

4.前台页面接收

 

    $(document).ready(function(){
        $.getJSON("/ashx/Ajax.ashx",{m:"test"},function(json){
            $.each(json,function(i,item){
                $("#test").append(item.ID+"."+item.FirstName+"
");
            })
        })
    });

 

$(document).ready(function(){
        $.getJSON("/ashx/Ajax.ashx",{m:"test"},function(json){
           
            var tb=$("#tb_name_list");
            tb.find("tr").each(function(i){  //清空表,保留第一行
                if (i>0) $(this).remove();
            });
     
            $.each(json,function(i,item){
                var tr=""+item.ID+""+item.FirstName+""+item.LastName+"";
                tb.append(tr);
            })
        })
    });

0
0

« 上一篇:Serializing and deserializing JSON
» 下一篇:net中  类、方法作为参数传递的写法整理。(通过反射实现)(即传递类、传递方法的实现)

你可能感兴趣的:(asp.net,ajax)