javascript - jquery.click 之后更新 HTML 页面

标签 javascript jquery html asp.net asp.net-mvc

我有一个 onclick 函数,它基本上只返回排序数据,如下所示:

$(document).ready(function () {
    $(".feedbackClick").click(function () {
       $.post("/Analyze/GetSortedByFeedback")
              .done(function (data) {
                  var sellers = $('<table />').append(data).find('#tableSellers').html();
                  $('#tableSellers').html(sellers);
              });
       });
    });
});

这就是我在 jquery 发布后尝试更新的表格的样子:

<table id="tableSellers" class="table table-striped jambo_table bulk_action">
    <thead>
       <tr class="headings">
            <th class="column-title"><h4><i class="fa fa-user" style="text-align:center"></i> <span>Username</span></h4> </th>
            <th class="column-title"> <h4><span class="glyphicon glyphicon-tasks salesClick" aria-hidden="true"></span></h4></th>
            <th class="column-title"><h4><i class="fa fa-star feedbackClick"></i></h4></th>

       </tr>
    </thead>
    <tbody>
       @foreach (var item in ViewBag.rezultati)
       {
             <tr>
                 <td><a href="http://ebay.com/usr/@item.StoreName" target="_blank">@item.StoreName</a></td>
                 <td>
                    <b>
                    @item.SaleNumber
                    </b>
                 </td>
                 <td><b>@item.Feedback</b></td>                                                   
             </tr>
       }

    </tbody>
</table>

点击基本上只是获取结果并更新 HTMl 中的表格...

有人可以帮我吗?

编辑:

当前方法不起作用...我触发了事件但没有任何反应...Action 中的代码被正确调用,但结果未显示...

编辑2:

这是.done之后数据对象的内容:

System.Collections.Generic.List`1[WebApplication2.Controllers.ResultItem]

编辑3:

这是操作:

public List<ResultItem> GetSortedByFeedback()
{
    return lista.OrderByDescending(x => x.Feedback).ToList();
}

编辑4这是 Alexandru 帖子后的数据:

Array[100]

现在我可以做:

data[0].Feedback

这在控制台中输出:

61259

最佳答案

请使用这个:

public JsonResult GetSortedByFeedback()
{
   var list=lista.OrderByDescending(x => x.Feedback).ToList();
   return Json(list);
}

如果您的方法是GET,请使用此:

public JsonResult GetSortedByFeedback()
{
   var list=lista.OrderByDescending(x => x.Feedback).ToList();
   return Json(list,JsonRequestBehavior.AllowGet);
}

那么请使用这个:

 .done(function (data) {
      $('#tableSellers tbody').empty();
      $.each(data,function(i,item){
           var tr='<tr><td><a href="http://ebay.com/usr/'+item.StoreName+'" target="_blank">'+item.StoreName+'</a></td><td><b>'+item.SaleNumber+'</b></td><td><b>'+item.Feedback+'</b></td></tr>';
           $('#tableSellers tbody').append(tr);//append the row
      });
  });

关于javascript - jquery.click 之后更新 HTML 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40359953/

相关文章:

javascript - 为什么此模式无法使用此代码打开。它仍然重定向,但模式不会弹出

html - 菜单项不在同一水平线上

javascript - 如何使用 selenium 获取所有元素的直接子元素和 css 选择器?

javascript - e.preventDefault - 有没有办法做默认?

javascript - 如何使用带有渲染 Prop 的 react-popper

html - 没有表格布局的表格的液体调整大小行为 :fixed?

php - 我怎样才能得到 table 外的图像?

javascript - 如何在 p5.js 中使用 dist() 来解释旋转?

jQuery 找到最近的父级 Div

javascript - jQuery Cycle - 跟踪循环中每个图像被查看的次数