【问题标题】:How to append data table in html table using json?如何使用json在html表中追加数据表?
【发布时间】:2014-02-10 08:49:51
【问题描述】:

我需要使用 ajax 方法在 html 表格中显示所有表格夹具布局,但它不起作用我不知道问题,请有人帮助我的朋友和我的代码。 . .

控制器 JsonResult

 public JsonResult FixturesVal(string TournamentName, string GroupName, string MatchDate, string MatchType, string GroundName, string MatchName, string TeamA, string TeamB, string Schedule)
    {
        string League = "";
        DateTime MatchPlayedOn = DateTime.ParseExact(MatchDate, "dd-MM-yyyy", CultureInfo.CurrentCulture);
        if (MatchType == "League")
        {
            League = objdetails.LeagueValidation(TournamentName, GroupName, MatchPlayedOn, MatchType, GroundName, TeamA, TeamB,Schedule);
        }

        if (League == "OK")
        {
            objdetails.AddFixture(TournamentName, GroupName, MatchType, MatchPlayedOn, Schedule, GroundName, MatchName, TeamA, TeamB,"New Tournament");
            League = objdetails.Save();
        }

        //var FixtureLayout = objdetails.TeamsForFixtures(TournamentName);
        int value = objdetails.Number(TournamentName, GroupName);
        var data = new { League, value };            
        return Json(data, JsonRequestBehavior.AllowGet);
    }

我的 Jquery

    $.post("/Fixtures/FixturesVal", { TournamentName: TournamentName, GroupName: GroupName, MatchDate: date, MatchType: MatchType, GroundName: ground, MatchName: $('#MatchCount').val(), TeamA: TeamA, TeamB: TeamB, Schedule: sche }, function (result) {
      $('#MatchCount').val("M" + result.value);
              $.each(result.FixtureLayout, function (i, value) {
                   tbody += '<tr><td>' + value.GroupName + '</td><td>' + value.MatchDate + '</td></tr>';
               });
       alert(tbody);
},"json");

此功能无效

【问题讨论】:

  • 不工作是什么意思?还要发布您的完整 Action 方法吗?
  • 不等我把我的完整帖子
  • 不工作是什么意思?你是否从 alert(tbody) 得到任何结果。?
  • no 没有收到任何警报信息

标签: javascript jquery asp.net-mvc json


【解决方案1】:

关于 javascript 中的一般错误检测:

启动浏览器控制台并检查错误。

您可能希望在您的$.post() 调用中添加一个.fail 回调:

$.post(...).fail(function(){  console.log('error', arguments);  });

查看您的请求是否失败。


关于您的具体问题:

尝试在$.post() 调用中指定dataType 参数:

$.post(url, {...}, function(result){...}, "json")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2016-12-17
    • 2013-05-13
    相关资源
    最近更新 更多