我與mvc4和C#的工作的getJSON沒有得到任何數據
我有一個控制器動作一樣,
[HttpGet]
public JsonResult GetChildCategories(int id)
{
Category cat = new Category(id);
List<Category> child = new Categories().ToList(cat); //get two list items when jquery calling
return Json(child, JsonRequestBehavior.AllowGet);
}
,我嘗試使用jQuery來調用這些動作,
$(document).ready(function() {
var url = '/Add/GetChildCategories/1';
$.getJSON(url, function (data) {
alert(data); //alert is not working
$.each(data, function (key, val) {
alert(key); //alert is not working
});
});
});
在調用這些時,列表child
包含兩項,但該值不在data
中。
你的GetChildCategories被調用嗎? – vallabha 2014-10-30 06:39:05
@vallabha:是的,它被調用,並在列表中有值 – shyama 2014-10-30 06:39:53
如果你直接從瀏覽器中打開URL會發生什麼?你是否得到一個帶有記錄的json文件下載?也嘗試使用:url ='@ Url.Action(「GetChildCategories」,「ControllerName」,new {id = 1})' – 2014-10-30 06:40:21