How do I return JSON and loop through the returned json in jQuery in MVC app?

前端 未结 4 850
情书的邮戳
情书的邮戳 2021-01-06 09:13

I have an MVC controller that returns JSON. I want to read/get that JSON using jQuery and loop through the json items/rows.

Basically I am reading bunch of comments

4条回答
  •  星月不相逢
    2021-01-06 09:48

    $.ajax(
        {
            type: "GET",
            url: "/comment/GetComments",
            dataType: "json",
            data: "blog_id=100&page_size=5&page_no=1",
            success: function (result) {
                jQuery.each(result['comments'], function(key,val){
                   // do stuff :)
                });
            },
            error: function (req, status, error) {
                alert('Error getting comments');
            }
        });
    

提交回复
热议问题