ie421.NET

面对技术,你别无选择,.NET世界是如此精彩,而我们要做的就是:Thinking More

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

1.json :Newtonsoft.Json https://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+"<br/>");
            })
        })
    });

 

$(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="<tr><td>"+item.ID+"</td><td>"+item.FirstName+"</td><td>"+item.LastName+"</td></tr>";
                tb.append(tr);
            })
        })
    });

posted on 2008-08-19 17:57  ie421  阅读(3038)  评论(2编辑  收藏  举报