1

MVC3 で AJAX を使用してテーブルを動的にロードしようとしています。これが IE9 の互換モードでしか機能しないのはなぜですか? それを回避する方法はありますか?

見る:

<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<script type="text/javascript">

    $.ajax({
        type: 'POST',        
        url: "/Index/GetApplicationsForUserJSON",       
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#ApplicationsForUser tbody").append("<tr>" +
                            "<td>" + data[i].Application + "</td>" +
                            "<td>" + data[i].Roles + "</td>" +
                        "</tr>");
            }

            $("tr:odd").css({ 'backgroundColor': '#ebf0f5' });            
        }
    });

</script>

        <table id="ApplicationsForUser" class="ui-widget ui-widget-content" style="width: 99%;
            margin: 3px 0px 0px 3px">
            <thead>
                <tr class="ui-widget-header ">
                    <th style="width: 45%">
                        Application
                    </th>
                    <th style="width: 45%">
                        Roles
                    </th>                    
                </tr>
            </thead>
        </table>

コントローラ:

  public JsonResult GetApplicationsForUserJSON()
        {

            Dictionary<string, string> tableData = new Dictionary<string, string>();
            tableData.Add("row1", "row1data");

            var jsonData = tableData
                          .Select(c => new
                          {
                              Application = c.Key,
                              Roles = c.Value
                          });

            return Json(jsonData, JsonRequestBehavior.AllowGet);

        }

編集:写真!

互換モード オフ

互換モードオン

4

2 に答える 2

1

あなたの例には tbody 要素がありません。ただし、 .append() 呼び出しのセレクターには 1 つが含まれています。おそらく互換性モードでは、IE9 はテーブルのコンテンツとして tbody の存在を「想定」しています。

于 2012-07-05T12:27:25.933 に答える
0

一部のブラウザは、想定されていない場合でもデータをキャッシュするため、一部のブラウザ要素はユーザーの要求で更新されません。そのため、コントローラー レベルでこれを指定して強制する必要があります。

[OutputCache(NoStore = true, Duration = 0)]

これにより、以前のリクエストからのリクエスト関連データを保存しないようにブラウザに指示します。

于 2012-07-05T12:02:05.723 に答える