Eventuali duplicati:
How do I return JSON and loop through the returned json in jQuery in MVC app?Come posso eseguire il loop dei dati JSON restituiti da jQuery?
Questo è il mio dati restituiti dal Controller MVC e ottengo questo nel mio successo di callback:
[{ "_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 } }
]
Controller:
[HttpGet]
public JsonResult GetComments(params...)
{
return Json(new { comments = GetFromDB().ToJson() }, JsonRequestBehavior.AllowGet);
}
Problema: Ho provato diversi modi per eseguire il loop delle righe. Ma tutto sembra un ciclo infinito.
$.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);
}
});
cercato anche:
$.each(result["comments"], function (key, value) {
alert('comment found');
});
come posso ciclo le righe & di accesso il valore di ogni attributo?
ciò che fa la tua ajax chiamata assomigliare? –
per favore modifica il tuo post piuttosto che incollare il codice in commment – mcgrailm
hai postato praticamente la stessa cosa oggi a: http://stackoverflow.com/questions/5953761/how-do-i-return-json-and-loop-through-the -returned-json-in-jquery-in-mvc-app/5954010 # 5954010 –