Reputation: 849
I am trying to do cross-domain requests (GET, POST, DELETE...) with Angular and NodeJs via CORS. I am successful when I try on Chrome browser but on IE11 on Win7 I get errors below.
SEC7118: XMLHttpRequest for http://master.domain:1300/login required Cross-Origin Resource Sharing (CORS).
SEC7119: XMLHttpRequest for http://master.domain:1300/login required CORS preflight.
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
Master domain side I set header Access-Control-Allow-Origin
so successfully working on Chrome.
I have tried xdomain library but I could not succeed with Angular. I may miss something but I do not know what. There is no example on the internet.
What can I do to work this on IE? I can use any other way except CORS.
Any help?
Thanks
Upvotes: 0
Views: 1764
Reputation: 31
Just try this code in nodejs side it's working
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4200');
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
Upvotes: 0
Reputation: 4912
Just setting "Access-Control-Allow-Origin" header might not be enough, dependent on the type of request you're making. You should also set the "Access-Control-Allow-Methods" and "Access-Control-Allow-Headers"
As an example:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS
Access-Control-Allow-Headers: Content-Type
Upvotes: 1