本文介绍了我可以为所有 AJAX 请求设置全局标头吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎不起作用:
$.ajaxSetup({
headers: {
Accept: 'application/vvv.website+json;version=1 ',
Authorization: 'Token token="FuHCLyY46"'
}
});
我本来以为会的.如果我将这些过滤器专门添加到我的 AJAX 调用中,那么它们确实可以工作.我想对所有 AJAX 调用全局执行此操作.
I would have thought it would. If I add these filters specifically to my AJAX call then they do work. I'd like to do this globally for all AJAX calls.
推荐答案
我做了一些额外的测试,你发布的代码运行良好.如果您在设置参数时遇到问题,您可以随时调用 beforeSend 并自己修改 xml 请求.
I did some additional tests and the code you posted works perfectly. If you have problems with something in how the parameters are setup, you could always to go the beforeSend call and modify the xml request yourself.
$.ajaxSetup({
beforeSend: function (xhr)
{
xhr.setRequestHeader("Accept","application/vvv.website+json;version=1");
xhr.setRequestHeader("Authorization","Token token="FuHCLyY46"");
}
});
这篇关于我可以为所有 AJAX 请求设置全局标头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!