Powiel możliwe:
How do I return JSON and loop through the returned json in jQuery in MVC app?Jak zapętlić dane JSON zwrócone przez jquery?
To moje dane zwracane przez kontrolera MVC i mam to w moim sukcesie zwrotnego:
[{ "_id" : { "$oid" : "4dc8" }, "eid" : { "$oid" : "4da" }, "user" : "bob", "text" : "First comment!!", "dt" : { "$date" : 1304966277978 } },
{ "_id" : { "$oid" : "4dc8" }, "eid" : { "$oid" : "4da" }, "user" : "bob", "text" : "Second comment!!", "dt" : { "$date" : 1304966347677 } },
{ "_id" : { "$oid" : "4dc8" }, "eid" : { "$oid" : "4da" }, "user" : "bob", "text" : "Third comment!!", "dt" : { "$date" : 1304966493240 } }
]
Kontroler:
[HttpGet]
public JsonResult GetComments(params...)
{
return Json(new { comments = GetFromDB().ToJson() }, JsonRequestBehavior.AllowGet);
}
Problem: Próbowałem kilka sposobów pętli wierszy. Ale wszystko wydaje się nieskończoną pętlą.
$.ajax(
{
type: "GET",
url: "/comment/GetComments",
dataType: "json",
data: "app=" + app + "&eid=" + eid + "&pg=" + pg + "&pgs=" + pgs,
success: function (result) {
$.each(result[comments], function() {
$.each(this, function (k, v) {
alert('this a column or attribute');
});
alert('end of row');
});
},
error: function (req, status, error) {
alert('Error=' + error + ' & Status=' + status);
}
});
próbował również:
$.each(result["comments"], function (key, value) {
alert('comment found');
});
Jak mogę pętli wiersze & dostępu wartość każdego atrybutu?
co robi swój ajax połączeń wyglądać? –
edytuj swój wpis, zamiast wklejać kod w commem – mcgrailm
opublikowałeś zasadniczo to samo dzisiaj na: http://stackoverflow.com/questions/5953761/how-do-i-return-json-and-loop-through-the -release-json-in-jquery-in-mvc-app/5954010 # 5954010 –