$ http.delete returns an error without information

I have a weird problem with AngularJS and the REST web service. This is my code:

$http.delete(appSettings['baseUrl'] + 'pricelistitem/' + article.itemNumber + '/' + article.acc) .error(function(e) { console.log(e); }); 

When you call this, I get an error and a .error is executed, but the object is e null .

In the console, I get this error:

 XMLHttpRequest cannot load <url>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access. 

When you make a DELETE request at the postman (the one that is called by my code), I get these headers in the response:

 Access-Control-Allow-Methods β†’ GET, POST, PUT, DELETE, OPTIONS Access-Control-Allow-Origin β†’ * Content-Length β†’ 2 Content-Type β†’ application/json Date β†’ Fri, 29 May 2015 06:26:00 GMT X-Powered-By β†’ IBM i 

I would say that these headers are correct and I should not get this error. Even if I did, the error object would be null and therefore would not show me any information.

UPDATE 15/06: This problem occurs when trying to use PUT and DELETE. POST and GET are working fine. On the Network tab of Chrome dev tools, I can only see the OPTIONS request. Access-Control-Allow-Methods NOT present in this request (but it is in PUT / DELETE when testing this in Postman), even after configuring Apache to include this header in every response.

I have been working for hours on this issue without any results.

What can cause this problem? Does the OPTIONS request also need to return the Access-Control-Allow-Origin header?

Any advice would be greatly appreciated!

+5
source share
2 answers

No header "Access-Control-Allow-Origin" is present on the requested resource

You have encountered the Cross Domain problem and what you need to do is enable CORS for your part.

+2
source

What is the cros problem and how to solve it

On the client side, you need to set this value for a while or try the Chrome cross plugin for testing to check if this is a cross-domain error or another issue

or try this $ httpProvider

and see this link Enabling CORS in Angular JS

<i>

 $httpProvider.defaults.headers.get = { 'Access-Control-Allow-Origin': '*' }; $httpProvider.defaults.headers.get = { 'Access-Control-Request-Headers': 'X-Requested-With, accept, content-type' }; $httpProvider.defaults.headers.get = { 'Access-Control-Allow-Methods': 'GET, POST' }; $httpProvider.defaults.headers.get = { 'dataType': 'jsonp' }; 

0
source

All Articles