为什么在MVC3中使用Ajax动态加载表只能在兼容模式下工作? [英] Why does loading a table dynamically using ajax in MVC3 only work in compatability mode?

查看:55
本文介绍了为什么在MVC3中使用Ajax动态加载表只能在兼容模式下工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MVC3中的AJAX来动态加载表.为什么这仅在IE9中的兼容模式下起作用?有办法解决吗?

I'm trying to get a table to load dynamically using AJAX in MVC3. Why does this only work in compatibility mode in IE9? Is there a way around it?

视图:

<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);

        }

图片!

推荐答案

在您的示例中没有看到tbody元素.但是,用于.append()调用的选择器包括一个.也许在兼容模式下,IE9会假设"表体作为表的内容.

I do not see a tbody element in your example. Your selector for the .append() call includes one, though. Perhaps in compatability mode, IE9 is "assuming" the presence of the tbody as the table's content.

这篇关于为什么在MVC3中使用Ajax动态加载表只能在兼容模式下工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆