ajax json 数据
2009-01-14 13:52
113 查看
json_ajax_Datable_IList(T).rar
使用datatable作为后台数据源
例子: 关于JSON的学习/学习json1_datatable.aspx; ToJson.ashx;
<script type="text/javascript">
</script>
{"Suppliers":[{"SupplierID":"1","CompanyName":"Exotic Liquids","Address":"49 Gilbert St.","City":"London","Country":"UK","Phone":"(171) 555-2222"},{"SupplierID":"2","CompanyName":"New Orleans Cajun Delights","Address":"P.O. Box 78934","City":"New Orleans","Country":"USA","Phone":"(100) 555-4822"},{"SupplierID":"3","CompanyName":"Grandma Kelly's Homestead","Address":"707 Oxford Rd.","City":"Ann Arbor","Country":"USA","Phone":"(313) 555-5735"},{"SupplierID":"4","CompanyName":"Tokyo Traders","Address":"9-8 Sekimai Musashino-shi","City":"Tokyo","Country":"Japan","Phone":"(03) 3555-5011"},{"SupplierID":"5","CompanyName":"Cooperativa de Quesos 'Las Cabras'","Address":"Calle del Rosal 4","City":"Oviedo","Country":"Spain","Phone":"(98) 598 76 54"},
……………………………………
然后用EVAL()把后台传过来的responseText对象转化为js对象
然后用json.Suppliers[index].SupplierID
json.Suppliers[index].CompanyName等访问
比使用Msxml2.DOMDocument控件解析XML方便
handle
加入Newtonsoft.Json DLL
新建一个有supplierID,CompanyName两个字段的model类supplier
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
SuppliersBLL bll = new SuppliersBLL();
Northwind.SuppliersDataTable table = bll.GetSuppliers();
IList<Supplier> lst = reSupplierList(table);
context.Response.Write(JavaScriptConvert.SerializeObject(lst));
context.Response.End();
}
public IList<Supplier> reSupplierList(Northwind.SuppliersDataTable table)
{
IList<Supplier> lst = new List<Supplier>();
foreach (Northwind.SuppliersRow item in table)
{
Supplier model = new Supplier();
model.ID = item.SupplierID;
model.CompanyName = item.CompanyName;
lst.Add(model);
}
return lst;
}
使用datatable作为后台数据源
例子: 关于JSON的学习/学习json1_datatable.aspx; ToJson.ashx;
<script type="text/javascript">
</script>
{"Suppliers":[{"SupplierID":"1","CompanyName":"Exotic Liquids","Address":"49 Gilbert St.","City":"London","Country":"UK","Phone":"(171) 555-2222"},{"SupplierID":"2","CompanyName":"New Orleans Cajun Delights","Address":"P.O. Box 78934","City":"New Orleans","Country":"USA","Phone":"(100) 555-4822"},{"SupplierID":"3","CompanyName":"Grandma Kelly's Homestead","Address":"707 Oxford Rd.","City":"Ann Arbor","Country":"USA","Phone":"(313) 555-5735"},{"SupplierID":"4","CompanyName":"Tokyo Traders","Address":"9-8 Sekimai Musashino-shi","City":"Tokyo","Country":"Japan","Phone":"(03) 3555-5011"},{"SupplierID":"5","CompanyName":"Cooperativa de Quesos 'Las Cabras'","Address":"Calle del Rosal 4","City":"Oviedo","Country":"Spain","Phone":"(98) 598 76 54"},
……………………………………
然后用EVAL()把后台传过来的responseText对象转化为js对象
然后用json.Suppliers[index].SupplierID
json.Suppliers[index].CompanyName等访问
比使用Msxml2.DOMDocument控件解析XML方便
handle
加入Newtonsoft.Json DLL
新建一个有supplierID,CompanyName两个字段的model类supplier
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
SuppliersBLL bll = new SuppliersBLL();
Northwind.SuppliersDataTable table = bll.GetSuppliers();
IList<Supplier> lst = reSupplierList(table);
context.Response.Write(JavaScriptConvert.SerializeObject(lst));
context.Response.End();
}
public IList<Supplier> reSupplierList(Northwind.SuppliersDataTable table)
{
IList<Supplier> lst = new List<Supplier>();
foreach (Northwind.SuppliersRow item in table)
{
Supplier model = new Supplier();
model.ID = item.SupplierID;
model.CompanyName = item.CompanyName;
lst.Add(model);
}
return lst;
}
相关文章推荐
- Ajax处理JSON数据参考【学习笔记】
- ajax异步请求通过json取得响应数据
- 浅谈Ajax返回数据的3种格式——HTML、XML、JSON
- Ajax使用JSON数据格式
- ajax请求返回json数据弹出下载框的解决方法
- jquery的ajax异步请求接收返回json数据
- 在Ajax中使用JSON传递数据 [ZT]
- Ajax交互,浏览器接收不到服务器的Json数据(跨域问题)
- Ajax将数据封装为JSON格式数据
- 掌握 Ajax,第 10 部分: 使用 JSON 进行数据传输
- node如何接收ajax post方式传来的json类型数据
- jQuery通过Ajax向PHP服务端发送请求并返回JSON数据
- jquery用ajax方式从后台获取json数据后如何将内容填充到下拉列表
- 前台使用$.ajax()发送json数据,服务器响应后返回json数据实例(struts2+json+action)
- ajax数据请求2(json格式)
- spring mvc接收ajax提交的JSON数据,并反序列化为对象
- AJAX 跨域请求 - JSONP获取JSON数据
- IE9.0或者360下js(JavaScript、jQuery)不能正确执行(加载),按F12后执行正常;Firefox下ajax的success返回数据data(json、string)无法获取
- 通过Ajax post Json类型的数据到Controller
- ajax中解析json数据的方式