संभव डुप्लिकेट:
How do I return JSON and loop through the returned json in jQuery in MVC app?मैं jquery द्वारा लौटा JSON डेटा कैसे लूप करूं?
यह मेरा डेटा MVC नियंत्रक द्वारा दिया है और मैं अपने सफलता कॉलबैक में यह मिलता है:
[{ "_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 } }
]
नियंत्रक:
[HttpGet]
public JsonResult GetComments(params...)
{
return Json(new { comments = GetFromDB().ToJson() }, JsonRequestBehavior.AllowGet);
}
समस्या: मैंने पंक्तियों को लूप करने के कई तरीकों की कोशिश की। लेकिन सभी अनंत लूप लगता है।
$.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);
}
});
भी करने की कोशिश की:
$.each(result["comments"], function (key, value) {
alert('comment found');
});
कैसे कर सकते हैं मैं पाश पंक्तियों & पहुँच प्रत्येक विशेषता के मूल्य?
क्या की तरह अपने ajax कॉल दिखता है? –
कृपया – mcgrailm
में कोड चिपकाने के बजाय अपनी पोस्ट संपादित करें, मूल रूप से आज भी वही चीज़ पोस्ट की गई है: http://stackoverflow.com/questions/5953761/how-do-i-return-json-and-loop-through-the -returned-json-in-jquery-in-mvc-app/5954010 # 5954010 –