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);
})
})
});