admin管理员组文章数量:1426637
I mocking my API using Apiary.io. But somehow I cannot read any headers from response object using angularJS. And I am sure i have at least Content-Type: application/json correctly set-up by checking in firebug. Code in Angular should read headers correctly too as i can print them when sending request to somewhere else than apiary.io...
$http.get('').then(function(response) {
console.log("ok",response.headers('Content-Type'));
},function(response){console.log("err",response);});
I mocking my API using Apiary.io. But somehow I cannot read any headers from response object using angularJS. And I am sure i have at least Content-Type: application/json correctly set-up by checking in firebug. Code in Angular should read headers correctly too as i can print them when sending request to somewhere else than apiary.io...
$http.get('http://ies.apiary.io/some').then(function(response) {
console.log("ok",response.headers('Content-Type'));
},function(response){console.log("err",response);});
http://plnkr.co/edit/zMO0pXGsIdJkV0fZdBdw
Share Improve this question edited Feb 22, 2013 at 2:26 Almad 5,9237 gold badges37 silver badges53 bronze badges asked Jan 7, 2013 at 1:22 Jakub KucharJakub Kuchar 1,6652 gold badges23 silver badges40 bronze badges 2- Can you set up a Plunker or jsFiddle with the code so you can show us in context where it doesn't work? We can answer you much quicker that way. – Josh David Miller Commented Jan 7, 2013 at 5:15
- plunker – Jakub Kuchar Commented Jan 7, 2013 at 10:26
1 Answer
Reset to default 5It all boils down to a bug in firefox: https://bugzilla.mozilla/show_bug.cgi?id=608735
For CORS request, firefox is not returning anything for req.getAllRequestHeaders(), although req.getRequestHeader('Content-Type') returns properly.
Either FF bug has to be fixed or Angular must work around it (as jQuery does) or you must go deeper and use XmlHttpRequest instance directly.
This was maybe also related, but probably not the core issue:
However, few days ago, Apiary.io was not setting Max-Age
in CORS
headers. Thus, if you had a minimal blueprint, you might have CORS
pre-flight response cached and thus subsequent requests may be disallowed even if you added additional resources to your blueprint.
Max-Age
is now set to 10 seconds, so it should work properly. However, depending on your browser, pre-flight cache might still affect you. Try purging it or test this app in another browser.
本文标签: javascriptAngularJS and ApiaryIOcan39t read any response headersStack Overflow
版权声明:本文标题:javascript - AngularJS and Apiary.IO - can't read any response headers? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745480749a2660161.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论