日期:2014-05-17 浏览次数:20617 次
//偷懒的转换方法,直接调用eval方法,数据源通常是个集合
var rptDatas = eval(ajaxData);
var items = docuement.getElementById("items").getElementsByTagName("li");
var count = Math.min(rptDatas.lenght, items.length);
for(var i=0;i<count; i++){
//假设数据项有title和date属性
items[i].innerHTML = "标题:" + rptDatas[i].title + " 日期:" + rptDatas[i].date;
}
public static string ToJsonString<T>(T obj)
{
var jsSer = new System.Web.Script.Serialization.JavaScriptSerializer();
StringBuilder output = new StringBuilder(32);
jsSer.Serialize(obj, output);
return output.ToString();
}
Ajax请求的后台页面loadData.ashx
List<Test> tests = 数据源;
Response.Write(ToJsonString(tests));
Response.End();