title: how to asynchronously get data using ajax and php
body: <p>i am new in ajax. i want to display the text entered inside the input to another div element.here is the image given below:</p>
  
  <p><a href="https://i.stack.imgur.com/tdhsU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tdhsU.png" alt="enter image description here"></a></p>
  
  <p>here is my code :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;label for="bar"&gt;Enter Text&lt;/label&gt;
      &lt;input id="bar" name="bar" type="text" value="" /&gt;   
  
  
  &lt;!-- The result of the search will be rendered inside this div --&gt;
  &lt;div id="result"&gt;Text Output: &lt;/div&gt;
  
  &lt;script &gt;
   /* Get from elements values */
   var values = $(this).serialize();
  
   $.ajax({
          url: "testajax.php",
          type: "post",
          async:true,
          data: values ,
          success: function (response) {                     
  
          },
          error: function(jqXHR, textStatus, errorThrown) {
             console.log(textStatus, errorThrown);
          }
  
  
      });
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>here is php code:</p>
  
  <pre><code>&lt;?php
    $bar = $_POST['bar']
  ?&gt;
  </code></pre>
  
  <p>please help me to fix the problem &amp; also minimize the code if possible.thanks </p>