ajax getitemlist
// Get the json from the controller
function GetListItems() {
$.ajax({
type: "POST",url: "/JsonService/GetItems",contentType: "application/json; charset=utf-8",data: "{}",dataType: "json",success: function (result) {
DisplayListItems(result);
},"error": function (result) {
var response = result.responseText;
alert('Error loading: ' + response);
}
});
}
// Create list items and append them inside
- element
function DisplayListItems(list) {
$.each(list,function(index,element) {
var itemHTML = ["
","$(".list > ul").append(itemHTML);
}
}
// Controller method that serves json data
public JsonResult GetItems()
{
IQueryable itemList = new DAO().GetList();
return Json(from e in itemList
select new
{
Title = e.Title,Description = e.Description
});
}
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。