title: passing variable from one ajax function to another ajax function
body: <p>I am new to php and ajax things. i want to know that is it possible to pass a variable from one ajax success function to another ajax data field. following are two ajax calls.</p>
  
  <pre><code>$("#submit_btn").on("click",function(e) {
      $.ajax({
      url: "./script.php",
      type: 'POST',
      data: {
          name: $('#clientName').val(),
          email: $('#clientEmail').val(),
          question: $("#quiz").val()
      }
  }).done(function(data){
          //alert(data);
          //console.log(data);
  
  });
  
  });
  </code></pre>
  
  <p>On first success function return clientName. Now i want to send this clientName in insert.php through second ajax call. The second ajax call is as follows:</p>
  
  <pre><code>$("#chat_send_btn").on("click",function(e) {
      $.ajax({
      url: "./insert.php",
      type: 'POST',
      data: {
              textarea:$('#hidden_textarea').val(document.getElementById('text_area').innerHTML),
              customerName: data
      }
  
  }).done(function(data){
      $('html, div').animate({scrollTop: $('#chat_messages_area').height()+5000});
  });
  </code></pre>
  
  <p>});</p>
  
  <p>this is insert.php. is it ok or am i doing something wrong?</p>
  
  <pre><code>&lt;?php
  session_start();    
  require 'connect.php';
  $uname ='';
  $msg = '';
  $tableName= "logs";
  if(isset($_POST['textarea']) &amp;&amp; isset($_POST['data']))
  {
     $msg = $_POST['textarea'];
     $uname = $_POST['data'];
     $sql_insertquery = "INSERT INTO `logs` (`msgID`, `username`, `msg`) VALUES (NULL, '$uname', '$msg');";
     $sth = $conn-&gt;query($sql_insertquery);
     $sql_selectquery = "SELECT * FROM logs";
  
  }
  else{echo "error";}
  ?&gt;
  </code></pre>