title: How to get the value from a textbox jquery and ajax?
body: <p>I am trying to get a value from a textbox and to post it on table, but when I try to console.log the "data" inside the success:function (data), it shows empty data. But if I console it outside the $.ajax it displays the right value.</p>
  
  <p>here's my jquery function</p>
  
  <pre><code>function SaveData() {
  
              var data = $("#inputToDo").val();
              $.ajax({
                  type: "POST",
                  dataType: "json",
                  success: function (data) {
                      var row = "";
                      $.each(data, function (index, value) {
                          console.log(data);
                          row += "&lt;tr&gt;&lt;td&gt;" + data + "&lt;/td&gt;&lt;/tr&gt;";
                          $("#bod").html(row);  
                      });
                  }
              });
              console.log(data);
              data = $("#inputToDo").val("");
              $("#inputToDo").focus();
  
      }
  </code></pre>
  
  <p>my html :</p>
  
  <pre><code>&lt;input id="inputToDo" name="inputToDo" /&gt;
  &lt;button id="buttonSave" name="buttonSave" onclick="SaveData()"&gt;
      Save
  &lt;/button&gt;
  
  &lt;table id="tableToDo" border="1"&gt;
      &lt;tr&gt;
          &lt;td id ="ToDo"&gt;&lt;/td&gt;
          &lt;td id ="Execution"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tbody id="bod"&gt;&lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>any help would be appreciated. thank you</p>