如何将withCredentials添加到现有的jquery.get语句中

时间:2014-07-24 13:04:35

标签: javascript jquery ajax cors

我已经在javascript和jquery中编写了我的应用程序,并广泛使用了jquery.get,jquery.post和jquery.when。这对我的localhost进行了很好的测试,但现在我需要连接到另一台服务器上的api,我发现我必须将xhrFields:{withCredentials:true}添加到我的所有http请求中。有什么方法可以在我的jquery.get语句中包含它,还是我必须将它们全部转换为jquery.ajax语句?

1 个答案:

答案 0 :(得分:12)

尝试

$.ajaxSetup({xhrFields: { withCredentials: true } });

$(document).ready(function() {...});