title: Passing variable from ajax to php and it is not being passed
body: <p>I want to pass a variable value to php on same page using onClick</p>
  
  <p>I have been searching google for days and trying all the examples and can't get anything to work</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;?php
  
  if(isset($_POST['name']))
  {
      echo $YourName= $_POST['name'];
  }
  
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;
  
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script type="text/javascript"&gt;
   function msg(){
  
        var name = "JR"; 
  
      $.ajax({
        type: 'POST',
        data:  {name : name},
        cache: false,
        async:false,
        success: function(data){
          $('#results').html(data);
        }
      })
   }
      msg(); 
  &lt;/script&gt;
  &lt;button type="button" onClick="msg();"&gt;Click Me!&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>should pass value to the php part of the page</p>