0

I have an ajax code that takes in 2 string parameters and passes those parameters to a behind code c# method that updates the user record in the database.

Here is my code:

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

Now when I try and run the code in IE 11, I get "Unable to get property 'stringify' of undefined or null reference" exception.

does anyone know what the problem could be? I am using Jquery 1.7 possibly I need to update to the latest version? Its possible that my ajax code is wrong?

I tried debugging with dev tools in IE and thought mayb IE 11 does not support stringify?

Let me know! Thanks.

Learn12
  • 206
  • 1
  • 3
  • 11
  • https://github.com/douglascrockford/JSON-js – Mohit Bhardwaj May 04 '16 at 15:12
  • http://stackoverflow.com/questions/5093582/json-is-undefined-error-in-ie-only – nurdyguy May 04 '16 at 15:12
  • Thanks guys, the problem lies in IE 11 for me though not IE 8. Do you think I should import JSON3? – Learn12 May 04 '16 at 15:16
  • Is IE11 definitely running in Standards mode, and not Quirks mode? Quirks mode does not support JSON.stringify: https://msdn.microsoft.com/library/cc836459%28v=vs.94%29.aspx?f=255&MSPPError=-2147217396 – ADyson May 04 '16 at 15:22
  • Ok everyone, Im using IE 11 and I went to the dev tools to see the document mode and it was set to 7 by default. The code works in 8,9,10,11 but my document mode was set to 7 and it would not work for that. I assume most people dont use IE 7 anymore so I might be safe – Learn12 May 04 '16 at 15:34

1 Answers1

1

I am using this

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

Worked for me in any browser