Leonid Bor
Leonid Bor

Reputation: 2264

How to turn off cors in Angular?

When using fetch you can set mode: 'no-cors' to avoid cors, is it possible with Angular's Http? The server I'm poking doesn't provide cors header, but I don't really need it as it gives the proper response right away, but because of cors issues my browser fires an exception and I cant execute code it subscribe() part.

UPD: Seems like it requires some JSONP trickery, but I've no idea how it works. Tried to replace Http with Jsonp, now I get JSONP injected script did not invoke callback. error.

Upvotes: 1

Views: 3629

Answers (1)

Leonid Bor
Leonid Bor

Reputation: 2264

Ok, figured that out. The server was just throwing JSONs back at me with no cors headers, that case is JSONP, had to replace Http with Jsonp and add a callback=JSONP_CALLBACK thing to request parameters. Also, request needed a header accept: application/json. After all those manipulations everything started working fine.

Upvotes: 1

Related Questions