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

前端 未结 4 877
情书的邮戳
情书的邮戳 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:59

    success: function(result) {
        $.each(result["comments"], function(key, value) {
            // loop
        });
    }
    

    Your result should be a json object

    {
        "comments": ...
    }
    

    As for the get failing try :

    type: "GET",
    url: "/comment/GetComments?blog_id=100&page_size=5&page_no=1",
    dataType: "json",
    //data: "blog_id=100&page_size=5&page_no=1",
    

提交回复
热议问题