title: Using AJAX to pass variable to PHP and retrieve those using AJAX again
body: <p>I want to pass values to a PHP script so i am using AJAX to pass those, and in the same function I am using another AJAX to retrieve those values. </p>
  
  <p>The problem is that the second AJAX is not retrieving any value from the PHP file. Why is this? How can I store the variable passed on to the PHP script so that the second AJAX can retrieve it? </p>
  
  <p>My code is as follows:</p>
  
  <p>AJAX CODE:</p>
  
  <pre><code>$(document).ready(function() {    
      $("#raaagh").click(function(){    
          $.ajax({
              url: 'ajax.php', //This is the current doc
              type: "POST",
              data: ({name: 145}),
              success: function(data){
                  console.log(data);
              }
          });  
          $.ajax({
              url:'ajax.php',
              data:"",
              dataType:'json',
              success:function(data1){
                  var y1=data1;
                  console.log(data1);
              }
          });
      });
  });
  </code></pre>
  
  <p>PHP CODE:</p>
  
  <pre><code>&lt;?php
  $userAnswer = $_POST['name'];    
  echo json_encode($userAnswer);    
  ?&gt;
  </code></pre>