我阅读了文档.
但我想我一定是误会了.
but I think I must have misunderstood it.
$http.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {
我也试过
$httpProvider.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {
我想把 Accept
改为 application/json
都不行.
使用 JSONP 时无法控制浏览器发送的标头.JSONP 是一个聪明的技巧(或黑客,取决于你如何看待它......),它包括插入一个指向服务器端点的 <script>
标记.最终,浏览器将决定在通过 <script>
标签请求脚本时发送哪些标头,而您无法影响它.
There is no way to control headers sent by a browser while using JSONP. JSONP is a smart trick (or a hack, depending on how you see it...) that consist of inserting a <script>
tag pointing to a server endpoint. Ultimately it is a browser who will decide which headers to sent while requesting scripts via <script>
tag and you can't influence it.
在此处了解更多信息:修改 JSONP 请求的 HTTP 标头
这篇关于如何更改 angularjs $http.jsonp 的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!