title: live search json data using ajax jquery
body: <p>I had been following this tutorial on how to live search through json with ajax and jquery</p>
  
  <p><a href="https://www.youtube.com/watch?v=gUofPxm0-IM" rel="nofollow noreferrer">https://www.youtube.com/watch?v=gUofPxm0-IM</a></p>
  
  <p>however the code does not work for my own json file as it does in the video when I run the page through my apache server. Does anybody know what im doing wrong?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --&gt;
      &lt;title&gt;Index&lt;/title&gt;
  
      &lt;!-- Bootstrap --&gt;
      &lt;link href="css/bootstrap.min.css" rel="stylesheet"&gt;
  
      &lt;!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --&gt;
      &lt;!-- WARNING: Respond.js doesn't work if you view the page via file:// --&gt;
      &lt;!--[if lt IE 9]&gt;
        &lt;script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"&gt;&lt;/script&gt;
        &lt;script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"&gt;&lt;/script&gt;
      &lt;![endif]--&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;div class="container"&gt;
    &lt;input type="search" class="form-control" id="search" /&gt;&lt;br/&gt;
    &lt;table class="table table-striped table-bordered table.hover"&gt;
    &lt;table&gt;
    &lt;thead&gt;
    &lt;tr&gt;
    &lt;th&gt;First name&lt;/th&gt;
    &lt;th&gt;Last Name&lt;/th&gt;
    &lt;th&gt;Phone Number&lt;/th&gt;
    &lt;th&gt;Address&lt;/th&gt;
    &lt;th&gt;picture&lt;/th&gt;
    &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
    &lt;/tbody&gt;
     &lt;/table&gt;
    &lt;/div&gt;
  
      &lt;!-- jQuery (necessary for Bootstrap's JavaScript plugins) --&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
      &lt;!-- Include all compiled plugins (below), or include individual files as needed --&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;&lt;/script&gt;
   &lt;script&gt;
   $('#search').keydown(function(){
   $.getJSON("address.json",function(data){
   var search = $('#search').val();
   var regex = new RegExp(search, 'i');
   var output;
   $.each(data, function(key, val)){
   if((val.first_name.search(regex) != -1) || (val.last_name.search(regex) != -1){
   output += "&lt;tr&gt;";
   output += "&lt;td id='"+key+"'&gt;"+val.first_name+"&lt;/td&gt;";
   output += "&lt;td id='"+key+"'&gt;"+val.last_name+"&lt;/td&gt;";
   output += "&lt;td id='"+key+"'&gt;"+val.phone+"&lt;/td&gt;";
   output += "&lt;td id='"+key+"'&gt;"+val.address+"&lt;/td&gt;";
   output += "&lt;td id='"+key+"'&gt;"+val.picture+"&lt;/td&gt;";
   output += "&lt;/tr&gt;";
   }
   });
   $('tbody').html(output);
   
   })
   
   &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>