title: Jquery POST fetching data on keyup
body: <p><strong>What I want to do</strong></p>
  
  <p>When writing in the text field, I want the <code>&lt;div class="result"&gt;</code> to be filled with what PHP is echoing.</p>
  
  <p>But it doesn't work!</p>
  
  <p><em>Jquery</em></p>
  
  <pre><code>$(document).ready(function() {
      var search = $("#search");
      if (search.val() !== '') {
          search.keyup(function() {
              $.post("index.php", { search : search.val()}, function(data) {
                  $(".result").html(data);
              });
          });
      }
  });
  </code></pre>
  
  <p><em>php</em></p>
  
  <pre><code>    if (isset($_POST['search'])) {
          echo 'hello';
      }
  </code></pre>
  
  <p><em>html</em></p>
  
  <pre><code>&lt;input type="text" name="search" id="search"/&gt;
  &lt;br /&gt;
  &lt;div class="result"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>When filling the input, nothing happens, and it meant to POST the entered data on keyup (When entering a new character/or deleting.</p>
  
  <p>What is stopping it from working? I am new to jQuery .</p>
  
  <p>Thanks.</p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt;
  </code></pre>