2014-02-10 37 views
3

我需要使用ajax方法在html表中顯示所有表夾具佈局,但它不工作我不知道這個問題,請有人幫助我的朋友和我的代碼。 。 。如何使用json在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"); 

此功能工作不

+0

你說的不工作呢?還發布完整的操作方法? – ramiramilu

+0

不用等我把我的全文發給 – Dinesh

+0

你是什麼意思不工作?你會得到任何警報結果(tbody)或不。 –

回答

0

關於JavaScript的一般錯誤檢測:

消防您的瀏覽器控制檯d檢查錯誤。

您可能需要一個.fail回調添加到您的通話$.post()

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

,看看你的請求失敗。


關於你提到的具體問題:

嘗試指定在$.post()調用dataType參數:

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