title: Access-Control-Allow-Origin - localhost
body: <p>I have problems with receiving json through ajax, the error is below. According to the information I've found so far regarding the error this seems to be some kind of cross domain issue, but I have no idea of what that means and how to solve it.</p>
  
  <p>There may be an issue with the response header (I have created the API myself and have no experiences since before), however a 200 OK is received if accessing the url directly in the browser.</p>
  
  <p>If accessing the url directly in the browser valid json is shown, so that shouldn't be the problem.</p>
  
  <p>How can this be solved?</p>
  
  <p><strong>Note: The url goes to an Apache server, not a file that has been the case for 95% of the questions here on Stack that I've read about the issue.</strong></p>
  
  <h2>Error in inspector:</h2>
  
  <pre><code>XMLHttpRequest cannot load http://localhost/api/v1/products?_=1355583847077.
  Origin null is not allowed by Access-Control-Allow-Origin.
  Error: error 
  </code></pre>
  
  <h2>The code:</h2>
  
  <pre><code>    $.ajaxSetup ({
        url: "http://localhost/api/v1/products", // &lt;--- returns valid json if accessed in the browser
        type: "GET",
        dataType: "json",
        cache: false,
        contentType: "application/json"
      })
      $.ajax({
          success: function(data){
  
              console.log("You made it!");
          },
          error: function(xhr) {
             console.log("Error: " + xhr.statusText);
         }
      }).done(function(data){
          console.log(data);
      })
  </code></pre>
  
  <h2>Params</h2>
  
  <p>_   1355583610778</p>
  
  <h2>Headers</h2>
  
  <p><strong>Response Headers:</strong></p>
  
  <pre><code>Connection  Keep-Alive
  Content-Length  3887
  Content-Type    application/json
  Date    Sat, 15 Dec 2012 14:50:53 GMT
  Keep-Alive  timeout=5, max=100
  Server  Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
  X-Powered-By    PHP/5.3.1
  </code></pre>
  
  <p><strong>Request Headers:</strong></p>
  
  <pre><code>Accept  application/json, text/javascript, */*; q=0.01
  Accept-Encoding gzip, deflate
  Accept-Language sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3
  Connection  keep-alive
  Host    localhost
  Origin  null
  User-Agent  Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Firefox/17.0
  </code></pre>
  
  <h2>Response</h2>
  
  <p>Nothing here...</p>