c# - jquery Ajax 调用导致 Firefox 中的未定义错误

标签 c# jquery ajax firefox

在过去的几个小时里,我一直在为这个问题而烦恼。谷歌搜索因这种非常模糊而受到阻碍。所以让我先为此道歉。

基本上,我使用 jquery 和 ajax(使用 C#)从后端返回数据并将其显示到屏幕上。该代码非常适用于 firefox 和 IE。但是当数据变得太大时(??)(1500+表行)我得到的只是一个未定义的弹出窗口。

在 firefox (3.6) 中调试它甚至没有进入成功方法。更糟糕的是,它甚至没有进入错误方法。那里有很多多余的信息,但我宁愿展示我正在做的一切。

代码

$j.ajax(
        {
            type: "POST",
            url: "AdminDetails.aspx/LoadCallDetails",
            data: "{" + data + "}",
            contentType: "application/json;charset=utf-8",
            dataType: "json",                
            success: function(msg) {
                $j("#CallDetailsHolder").html(msg.d);
                $j(".pointingHand").hide(); 

                var oTable = $j('#dt').dataTable({
                    "bProcessing": true,
                    "bPaginate": true,
                    "bSort": true,
                    "bAutoWidth": false,
                    "aoColumns": [
                        { "sType": 'html' },
                        { "sType": 'custdate' },
                       { "sType": 'html-numeric' },
                        { "sType": 'ariary' },
                        { "sType": 'html' },
                        { "sType": 'html' }
                    ],
                    "oLanguage": {
                        "sProcessing": "Traitement...",
                        "sLengthMenu": "_MENU_ Montrer",
                        "sZeroRecords": "Aucun enregistrement",
                        "sInfo": "_START_ à _END_ de _TOTAL_",
                        "sInfoEmpty": "0 à 0 de 0",
                        "sInfoFiltered": "(filtrée à partir de _MAX_ )",
                        "sInfoPostFix": "",
                        "sSearch": "Rechercher",
                        "sUrl": "",
                        "oPaginate": {
                            "sFirst": "premier",
                            "sPrevious": "Précédent",
                            "sNext": "suivant",
                            "sLast": "dernier"
                        }
                    },
                    "sDom": 'T<"clear">lfrtip'

                });

                $j('#CompteBlocRight0').unblock();

                $j('#btnRangeSearch').click(function() { oTable.fnDraw(); });

            },
            error: function(msg) {
                DisplayError(msg);
                $j('#CompteBlocRight0').unblock();
            }
        });               //$.ajax 
    }

代码绝对有效。甚至在 IE 中显示也没有任何问题。

有什么帮助吗???

最佳答案

由于它适用于小型数据集,而无法适用于大型数据集,因此您需要隔离大型数据集的失败案例。

使用 Firebug 中的网络选项卡查看服务器的响应。状态 2xx 应该进入成功处理程序,所有其他应该进入错误处理程序。也许您的服务器正在以某种方式让 Ajax 控件感到困惑?

对于这些类型的错误,简化代码以进行调试通常非常很有帮助。试试这段代码,将处理程序替换为简单的消息:

$j.ajax(
    {
        type: "POST",
        url: "AdminDetails.aspx/LoadCallDetails",
        data: "{" + data + "}",
        contentType: "application/json;charset=utf-8",
        dataType: "json",                
        success: function(msg) {
            console.log("in success handler");
        },
        error: function(xhr, textStatus, errorThrown) {
            console.log("in error handler: "+textStatus);
            console.dir(xhr);
            console.dir(errorThrown);
        }
    });               //$.ajax 
}

更新:您的错误处理程序的签名不正确。更新了我的示例。

关于c# - jquery Ajax 调用导致 Firefox 中的未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2491573/

相关文章:

c# - 根据 MainViewModel 中的状态启用/禁用不同 View 上的控件的最佳方法

javascript - 如何取消for循环内的所有ajax请求

JQuery ajax POST字符串参数,MVC操作方法获取null

jquery - 在拍卖中添加日期有困难

javascript - 在触发一次后删除 If 语句

jquery - 使固定定位的 div 继承父级的宽度而不是 body

php - AJAX、Laravel 4.2 - POST 状态已取消,如何发布到路由

c# - 无法添加实体类型 'X' 的种子实体,因为没有为所需属性 "..ID"提供值

javascript - 为 Excel 编写一个新函数

c# - linq to sql查询帮助——常用值