title: AngularJS: allow cross-domain AJAX request
body: <p>I am trying to invoke a REST web service from my new Angular app. When a request is made I am getting this error:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load <a href="http://localhost:8080/WebService" rel="nofollow noreferrer">http://localhost:8080/WebService</a>. No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>' is therefore not allowed access.</p>
  </blockquote>
  
  <p>I found out this is happening because the browser is not allowing such action.</p>
  
  <p>In StackOverflow <a href="https://stackoverflow.com/questions/22360700/error-message-xmlhttprequest-cannot-load-cross-origin-requests-are-only-suppor">one of the solutions</a> was to disable a few security options. I tried doing this and it didn't work, I was getting the same error.</p>
  
  <p>Then <a href="https://stackoverflow.com/questions/18712766/how-to-config-wamp-apache-server-to-allow-cross-domain-requests-of-ajax">another solution</a> suggested moving the project to a server. So I moved my project to my <code>www</code> folder in WAMP. It didn't work because I needed to activate the <code>headers_module</code> and then modify <code>httpd.conf</code> adding this:</p>
  
  <pre><code>&lt;IfModule mod_headers.c&gt;
      Header set Access-Control-Allow-Origin: *
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>So I activated the module and modified the general config file (can't remember how to do it just form my web project) and restarted WAMP. It still won't work.</p>
  
  <p>The only think I could do to make it work was creating a web project in Eclipse JEE and run it on a Tomcat server. But I don't really want to do this.</p>
  
  <p>How can I fix this problem?</p>
  
  <p><strong>Edit</strong> I also tried adding this to my angular app:</p>
  
  <pre><code>app.config([ '$httpProvider', function($httpProvider) {
      $httpProvider.defaults.useXDomain = true;
      delete $httpProvider.defaults.headers.common['X-Requested-With'];
  }]);
  </code></pre>
  
  <p>The issue remained.</p>