See discussion and request response dump here: https://developers.google.com/civic-information/docs/ci_forum?place=msg%2Fgoogle-civicinfo-api%2FfrDw1s9eyxs%2F12YwPFjI4u4J
@dougvk it looks like CORS request and it is a browser making the pre-flight OPTIONS request. There is a nice article on the topic: http://www.html5rocks.com/en/tutorials/cors/
I had a brief look at the discussion on the forum where it is suggested that this POST request should behave like simple GET but actually in your case there are more headers (and I suspect that you are sending JSON) so IMHO this is not so called "simple" CORS request.
ah, okay, so it turns out the framework requests with too many headers - https://developers.google.com/civic-information/docs/ci_forum?place=msg%2Fgoogle-civicinfo-api%2FfrDw1s9eyxs%2FJoXXqh0xmUYJ. is there a way to trim these down in angular?
@dougvk What is the version of AngularJS your are using? Asking since in 1.1.1
both x-requested-with
and x-csrftoken
(which probably are triggering pre-flight request in your case) those headers are not sent by default:
https://github.com/angular/angular.js/blob/master/CHANGELOG.md#111-pathological-kerning-2012-11-26
If you are using an earlier version you can remove those headers. See "Setting HTTP Headers" in http://docs.angularjs.org/api/ng.$http
I was running 1.0.4 - that was the problem! Thanks.
Add header to to post it will solve cors error.
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
after adding this option after url, header ...... It's working for me.
@gnganpath Yeah I added 'application/json' and it worked for me.
The documentation is great. Solve my problem
Most helpful comment
Add header to to post it will solve cors error.
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
after adding this option after url, header ...... It's working for me.