title: Jquery AJAX POST not passing anything to PHP
body: <p>I'm having a problem passing variable using POST method with AJAX.Jquery</p>
  
  <p>Here is my code:</p>
  
  <p>ajaxtest.php</p>
  
  <pre><code>&lt;?php 
    $dir = $_POST['dir'];
    $scaned = glob($dir."*",GLOB_ONLYDIR);    
    echo json_encode($scaned);
  ?&gt;
  </code></pre>
  
  <p>ajaxtest.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;script&gt;
  
  $(document).ready(function(){
  $('button[type="button"]').click(function(){
      var dir = 'gals/';
      $.ajax({
          url: "ajaxtest.php",
          type: "POST",
          data: dir,
          success: function(results){
              data = jQuery.parseJSON(results);
              for (var i = 0; i &lt; data.length ; i++) {
                  $('#buttonA').after('&lt;br /&gt;'+data[i]+'&lt;br /&gt;'); 
              };
  
          }
      })
  })
  
  })
  &lt;/script&gt;
  &lt;body&gt;
  &lt;br /&gt;
  &lt;button id="buttonA" type="button"&gt;Test button&lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This code not working.</p>
  
  <p><strong>But this one do:</strong> (but not with json)</p>
  
  <pre><code>$.post("ajaxtest.php", {dir:dir}, function(results){
          var data = $.parseJSON(results);
          for (var i = 0; i &lt; data.length ; i++) {
              $('#buttonA').after('&lt;br /&gt;'+data[i]+'&lt;br /&gt;'); 
          }
      })
  </code></pre>
  
  <p>why so?!
  What is wrong in my code? please advice!
  Thanks a lot.</p>