skip to Main Content

I have one variable in Jquery it which I am assigning the value at a button click. Now after the successful execution of the code, I want to make the variable null.

$("#btnAdd").click(function () {

var myDataVariable= {};

myDataVariable.dataOne="SomeData";
myDataVariable.dataTwo="SomeData";
myDataVariable.dataThree="SomeData";
   //Pass the value to Database
                $.ajax({
                 success: function (data) {
                   //If Successfully Inserted Data I want to make "myDataVariable" Null 
                 } 
               });
});

2

Answers


  1. $("#btnAdd").click(function () {
    
    var myDataVariable = {};
    
    myDataVariable.dataOne="SomeData";
    myDataVariable.dataTwo="SomeData";
    myDataVariable.dataThree="SomeData";
       //Pass the value to Database
                    $.ajax({
                     success: function (data) {
                       myDataVariable = null;
                       // you can use myDataVariable.attribute = null; if you want an attribute of this object to be null
                     } 
                   });
    });
    
    Login or Signup to reply.
  2. You can directly set it to null by applying myDataVariable = null;
    But I think it’s unnecessary because it will automatically reset next click .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search