Ajax如何获取后台数据显示到List
// 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 <ul> element function DisplayListItems(list) { $.each(list, function(index, element) { var itemHTML = ["<li>", "<div>", "<div>", element.Title, "</div>", "<div>", element.Description, "</div>", "</div>", "</li>"].join('\n'); $(".list > ul").append(itemHTML); } } // Controller method that serves json data public JsonResult GetItems() { IQueryable<Item> itemList = new DAO().GetList(); return Json(from e in itemList select new { Title = e.Title, Description = e.Description }); }
如果真苦,你哪有时间喊累。如果真惨,你哪有时间觉得丢脸。因为承受得还不够,所以你才有时间抱怨。人生总有太多的无奈和遗憾,因为这就是生活。
浙公网安备 33010602011771号