【问题标题】:Unable to get property 'stringify' of undefined or null reference IE 11 ASP.NET无法获取未定义或空引用 IE 11 ASP.NET 的属性“字符串化”
【发布时间】:2016-05-04 15:09:59
【问题描述】:

我有一个 ajax 代码,它接受 2 个字符串参数并将这些参数传递给一个后台代码 c# 方法,该方法更新数据库中的用户记录。

这是我的代码:

                    // Grabs the Customer_ID 
                    <%string inputCust = Session[SessionKey.CUSTOMER_ID].ToString();%>
                    var custNoString = "<%=inputCust%>"

                    // Final input for the password.
                    var finalValue = value2.value;

                    // Create the data object for the 2 parameters for the c# Method
                    var dataObj = {};
                    dataObj.custID1 = custNoString;
                    dataObj.tempPass2 = finalValue;

                        // { "custID1" : custNoString , "tempPass2" : finalValue };
                     // AJAX request to run the function
                     $.ajax({
                         type: "post",
                         url: "reciept.aspx/AddGuestAccount",
                         contentType: "application/json; charset=utf-8",
                         data: JSON.stringify(dataObj),
                         dataType: "json",
                         success: function(){

                             $("#Screen1").hide();
                             $("#Screen2").show(); 
                         },
                         error:function(error){ alert("We are sorry, the action failed. Error: " + error);} 
                     });
                     return true;

现在,当我尝试在 IE 11 中运行代码时,出现“无法获取未定义或空引用的属性 'stringify'”异常。

有谁知道问题出在哪里?我正在使用 Jquery 1.7 可能我需要更新到最新版本?是不是我的ajax代码有问题?

我尝试在 IE 中使用开发工具进行调试,并认为可能 IE 11 不支持 stringify?

告诉我!谢谢。

【问题讨论】:

  • 谢谢大家,问题在于我的 IE 11 而不是 IE 8。你认为我应该导入 JSON3 吗?
  • IE11 肯定在标准模式下运行,而不是在 Quirks 模式下运行吗? Quirks 模式不支持 JSON.stringify:msdn.microsoft.com/library/…
  • 大家好,我用的是IE 11,我去开发工具看看文档模式,默认设置为7。该代码适用于 8、9、10、11,但我的文档模式设置为 7,因此无法正常工作。我假设大多数人不再使用 IE 7,所以我可能是安全的

标签: javascript jquery asp.net ajax internet-explorer-11


【解决方案1】:

我正在使用这个

 var custNoString = "value1"

    // Final input for the password.
    var finalValue = "value2.value";

    // Create the data object for the 2 parameters for the c# Method
    var dataObj = {};
    dataObj.custID1 = custNoString;
    dataObj.tempPass2 = finalValue;
    $.ajax({
        type: "post",
        url: "about.aspx/diffData",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(dataObj),
        dataType: "json",
        success: function () {

            $("#Screen1").hide();
            $("#Screen2").show();
        },
        error: function (error) { alert("We are sorry, the action failed. Error: " + error); }
    });

在任何浏览器中都为我工作

【讨论】:

    猜你喜欢
    • 2015-11-01
    • 2018-09-29
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 2020-04-28
    • 2016-08-16
    • 2017-05-18
    相关资源
    最近更新 更多