【问题标题】:Load HTML5 Table Dynamically from ajax从 ajax 动态加载 HTML5 表格
【发布时间】:2013-07-18 22:08:29
【问题描述】:

我在 ASP.Net MVC4 中工作,在我看来我有一个表,想从 但成功后没有加载。

<div id="groupTable"> <table> table columns and rows <table></div>


$.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: { groupNames: JSON.stringify(groubyNames), page: JSON.stringify(page) },
            success: function(data) {
                   $('#groupTable').load(data); // not refreshing table withdata
            },
            error: function(request, status, error) {

                alert(request.responseText);
            }
        });

【问题讨论】:

    标签: jquery ajax asp.net-mvc html asp.net-mvc-4


    【解决方案1】:

    将负载改为html调用

    编辑:这是使用 json 数据创建表的方式

        $.ajax({
                    type: "POST",
                    url: url,
                    dataType: "json",
                    data: { groupNames: JSON.stringify(groubyNames), page: JSON.stringify(page) },
                    success: function(data) {
                         var table = $('<table/>');
                         $(data).each(function() {
                               var row = $('<tr/>');
                               row.append('<td>' + this.Value + '</td>');
                               row.append('<td>' + this.Value + '</td>');
                         });
                         table.append(row);                   
                         $('#groupTable').html(table); // not refreshing table withdata
                    },
                    error: function(request, status, error) {
    
                        alert(request.responseText);
                    }
                });
    

    【讨论】:

    • 你在成功函数中得到了什么数据。您能否验证这是您期望的 html 表。
    • var model = _unitOfWork.MenuSetRepository.Get().ToPagedList(groups, page, 10); var json = new JavaScriptSerializer().Serialize(model);返回 json;
    • @ineffablep 我的意思是你能用 console.log 调试 javascript 来查看服务器响应是什么
    • @ineffablep 也 Jquery 不知道如何从 json 数据构建表。您应该在成功函数中返回 html 或创建表格。
    • 嗨,我正在返回公共接口 IPagedList : IEnumerable { int PageIndex { get; } int PageSize { 得到; } int TotalCount { 得到; } int TotalPages { 得到; } bool HasPreviousPage { 获取; } 布尔 HasNextPage { 获取; } 字符串 GroupByNames { 获取; } Dictionary 组 { 获取; } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 2014-02-26
    • 2015-08-29
    • 2014-02-19
    • 1970-01-01
    • 2015-02-10
    相关资源
    最近更新 更多