Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular and CORS
    primarykey
    data
    text
    <p>I am writting app with angular 1.2 and I am trying to call to REST API on local glassfish 3.1. I am calling right that:</p> <pre><code>app.factory("shopModel", function($resource){ return $resource('http://localhost:8080/Schedule-service/shops', {}, { query: {method:'GET', headers: {'Content-Type': 'application/json'} params:{}} }); }); </code></pre> <p>But I get an error in my chrome.</p> <pre><code>XMLHttpRequest cannot load http://localhost:8080/Schedule-service/shops. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. </code></pre> <p>I added to my app config this code but this haven't helped:</p> <pre><code>app.config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; }]); </code></pre> <p>I don't know what to do. I will by thankful for every tip.</p> <p>Edit. I added headers_module to my apache wamp. And I added to my httpd.conf file this:</p> <pre><code>&lt;IfModule mod_headers.c&gt; Header set Access-Control-Allow-Origin: * &lt;/IfModule&gt; </code></pre> <p>But still don't work. Any suggestions??</p> <p>Edit2. Ok I resolve It. I've added this filter to my Spring web:</p> <pre><code> public class CorsFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept, x-requested-with, sid, mycustom, smuser"); filterChain.doFilter(request, response); } } </code></pre> <p>Thanks Quentin.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload