ajax请求头奇怪的行为
关于在不同浏览器之间设置接受标头,我遇到了一些奇怪的事情。
使用 Firefox 时,默认标头似乎是 text/html。然而,chrome 上的默认标头似乎是 application/json。
我已经清除了两者的浏览器缓存,但我仍然看到相同的行为。
我的目标是为简单的 REST API GET 设置标头类型,以便球衣资源可以协商适当的响应类型,但由于上述原因,我的行为不一致。
我相信我正在做一些非常愚蠢的事情,但如果有人能指出为什么我会经历上述情况,那将会有很大的帮助。
感谢
我设置的ajax标头如下,我相应地更改了标头类型。
myGetRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
I'm experiencing something somewhat strange with regards to setting the accept header between different browsers.
When using Firefox, the default header seems to be text/html. However the default header on chrome seems to be application/json.
I have cleared my browser cache for both and still I see the same behaviour.
My objective is to set the header type for a simple REST API GET so that the jersey resource can content negotiate the appropriate response type but due to the above I'm getting inconsistent behaviour.
I believe I'm doing something very silly but if someone can point out why I would experience the above that would be great help.
thanks
the ajax header I am setting is as follows and I change the header type accordingly.
myGetRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请求标头应该是“Accept”而不是“Content-Type”:
The request header should be 'Accept' not 'Content-Type':