首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用javascript函数时IE 7崩溃

调用javascript函数时IE 7崩溃
EN

Stack Overflow用户
提问于 2013-10-06 18:03:06
回答 1查看 146关注 0票数 0

我的asp.net mvc 4视图中有一个asp.net,在这个视图中,我定义了一种将用于jqGrid的类型。jqGrid位于jQuery选项卡中(我有一个jQuery选项卡组件)。

选项卡中的jqGrid插入如下:

代码语言:javascript
复制
  <div id="jqGrid">
      @Html.Partial("../Grids/_MyGrid")
  </div>

这是从如下视图中的ajax调用中调用的:

代码语言:javascript
复制
@using (Ajax.BeginForm("Search", "Item",
   new AjaxOptions
   {
       HttpMethod = "GET",
       InsertionMode = InsertionMode.Replace,
       UpdateTargetId = "jqGrid",
       OnSuccess = "showGridItems()"
   }))
{
    // My Stuff
}

在相同的视图中,我定义了将用于jqGrid的类型如下:

代码语言:javascript
复制
<script type="text/javascript">
    var paramFromView = {
        DeleteAllCaption: '@Resource.CaptionPagerDeleteAll',
        ClearGridUrl: '@Url.Content("~/Item/ClearGridData")',
        DeleteAllConfirmationMessage: '@Resources.Resource.ItemDeleteAllDataConfirmation',
        Url: '@Url.Content("~/Item/GetData")',
        Width: @width,
        Height: @height,
        Caption: '@Resources.Resource.ItemIndexTitle',
        ItemName: '@Resources.Resource.ItemIndexName',
        ItemAddress: '@Resources.Resource.ItemIndexAddress',
        ItemType: '@Resources.Resource.ItemIndexType',
        Actions: '@Resources.Resource.ItemIndexActions',
        PageSize: @pageSize,
    };

</script>

上面指示的部分视图_MyGrid也在相同的视图中类似于以下内容:

代码语言:javascript
复制
<table id="_itemGrid" cellpadding="0" cellspacing="0">
</table>
<div id="_itemPager" style="text-align: center;">
</div>

当执行ajax调用(参见上面的ajax代码)并获得成功时,下面的javascript函数被称为onsuccess:

代码语言:javascript
复制
function showGridItems() {
    $('#_itemGrid').jqGrid({
        caption: paramFromView.Caption,
        colNames: ['ID', paramFromView.ItemName, paramFromView.ItemAddress, paramFromView.ItemType, paramFromView.Actions],
        colModel: (...)
}

此函数在js文件中定义,并包含在以下视图中:

代码语言:javascript
复制
@section scripts
{
    @Content.Script("/Grids/ItemGrid.js", Url)
}

它在IE8、IE9和IE10中运行得很好,但在IE7中却在showGridItems中崩溃。错误是说没有定义paramFromView!我不知道为什么,因为从IE8到IE10都很完美,但对IE7却不起作用。发生什么事了呢?

更新了,它是由pageSize后面的逗号引起的。我已经搬走了,现在开始工作了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-06 18:06:04

从脚本中删除最后一个逗号(,)。

代码语言:javascript
复制
<script type="text/javascript">
var paramFromView = {
    DeleteAllCaption: '@Resource.CaptionPagerDeleteAll',
    ClearGridUrl: '@Url.Content("~/Item/ClearGridData")',
    DeleteAllConfirmationMessage: '@Resources.Resource.ItemDeleteAllDataConfirmation',
    Url: '@Url.Content("~/Item/GetData")',
    Width: @width,
    Height: @height,
    Caption: '@Resources.Resource.ItemIndexTitle',
    ItemName: '@Resources.Resource.ItemIndexName',
    ItemAddress: '@Resources.Resource.ItemIndexAddress',
    ItemType: '@Resources.Resource.ItemIndexType',
    Actions: '@Resources.Resource.ItemIndexActions',
    PageSize: @pageSize
};

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19212064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档