title: AJAX Live Search Not Showing Results
body: <p>Have a live search page as shown in livesearch.php below, when typing entries into the input box am not getting any results show under it. The html code and script in search.php are shown beelow.</p>
  
  <p><strong>search.php</strong></p>
  
  <pre><code>   &lt;!DOCTYPE HTML&gt;
      &lt;html&gt;
         &lt;header&gt;
              &lt;link href="css/main.css" rel="stylesheet" type="text/css"&gt;
              &lt;link href="css/search.css" rel="stylesheet" type="text/css"&gt;
         &lt;/header&gt;
         &lt;body&gt;
              &lt;div id="searchContainer"&gt;
                  &lt;div class="searchMainTitle"&gt;Search Schedules&lt;/div&gt;
                      &lt;div class="searchSubTitle"&gt;
                  &lt;p&gt;Enter any information you wish, this will search all schedule fields.&lt;/p&gt;
                  &lt;/div&gt;
              &lt;form role="form" method="post"&gt;
                  &lt;input type="text" class="form-control" size="100%" placeholder="Enter Search Term(s) Here" id="keyword" /&gt;
              &lt;/form&gt;
                      &lt;ul id="liveSearch"&gt;&lt;/ul&gt;       
  
          &lt;/div&gt;
          &lt;script type="text/javascript"&gt;
          $(document).ready(function() {
          $('#keyword').on('input', function() {
              var searchKeyword = $(this).val();
              if (searchKeyword.length &gt;= 3) {
          $.post('livesearch.php', { keywords: searchKeyword }, function(data) {
                      $('ul#liveSearch').empty()
                      $.each(data, function() {
                      $('ul#liveSearch').append('&lt;li&gt;&lt;a href="schedPopup.php?id=' + this.id + '"&gt;' + this.title + '&lt;/a&gt;&lt;/li&gt;');  
                      });
                  }, "json"); 
              }
          });
      }); 
          &lt;/script&gt; 
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The livesearch.php that is being referenced by the script is shown below</p>
  
  <p><strong>livesearch.php</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  
  require 'dbconnect.php';
  
  echo "Keyword: ".$_POST['keywords']."&lt;br/&gt;&lt;br/&gt;";
      $liveSearchArray = array();
          if (!empty($_POST['keywords'])) {
              $keywords = $connection-&gt;real_escape_string($_POST['keywords']);
              $sql = "SELECT OWNER_SURNAME,OWNER_FIRSTNAMES,OWNER_TITLE FROM testucm_owners WHERE OWNER_SURNAME LIKE '%".$keywords."%'";
              $result = $connection-&gt;query($sql);
              if ($result-&gt;num_rows &gt; 0) {
                  echo "We Have A Result, There Are ".$result-&gt;num_rows." Rows";
                  while ($obj = $result-&gt;fetch_object()) {
                      $liveSearchArray[] = array('id' =&gt; $obj-&gt;OWNER_SURNAME, 'title' =&gt; $obj-&gt;OWNER_TITLE);
                  }
              } else {
                  echo "No Matches";
              }
          }
  
   echo json_encode($liveSearchArray);
  
   mysqli_close($connection);
  ?&gt; 
  </code></pre>
  
  <p>If a manually add a value for keywords into the livesearch.php query I get the correct results, however no resutls display if I enter search terms via search.php. I have partially test this by putting an alert after <code>var searchKeyword = $(this).val();</code>, this shows the correct term as typed in however still no results showing.</p>
  
  <p>I suspect the error may be with this line of code:</p>
  
  <pre><code>$('ul#liveSearch').append('&lt;li&gt;&lt;a href="schedPopup.php?id=' + this.id + '"&gt;' + this.title + '&lt;/a&gt;&lt;/li&gt;'); 
  </code></pre>
  
  <p>Either that or for some reason the $liveSearchArray is not being passed back to the script, however I'm unable to determine where the error lies or how to fix it. Any help would be greatly appreciated</p>