title: Read json file from localhost with javascript
body: <p>I need to read a <code>.json</code> file from my localhost, but it didn't work!</p>
  <p>The contents of the file are as follows:</p>
  <pre><code>[
   {&quot;source&quot;:&quot;tw1&quot;, 
    &quot;text&quot;:&quot;fubar&quot;}, 
  
   {&quot;source&quot;:&quot;tw2&quot;, 
    &quot;text&quot;:&quot;foo&quot;}
  ]
  </code></pre>
  <p>I set up the localhost with the command: <code>python -m http.server 8888 &amp;</code>, which is posted <a href="https://github.com/mbostock/d3/wiki" rel="nofollow noreferrer">D3.js</a> here.</p>
  <p>I wrote the following javascript code:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot; src=&quot;lib/jquery-1.9.1.js&quot;&gt;&lt;/script&gt;
     &lt;script&gt;
      $(document).ready(
          $.getJSON(&quot;http://localhost/test.json&quot;, function(data){
              document.write(data);
  
      });
      &lt;/script&gt;  
   
  </code></pre>