最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I add withCredentials to existing jquery.get statements - Stack Overflow

programmeradmin3浏览0评论

I have written my application in javascript and jquery and have made extensive use of jquery.get, jquery.post and jquery.when. This works fine testing on my localhost, but now I need to connect to an api on another server I find I have to add xhrFields: { withCredentials: true }, to all my http requests. Is there any way I can include this in my jquery.get statement, or do I have to convert them all to jquery.ajax statements?

I have written my application in javascript and jquery and have made extensive use of jquery.get, jquery.post and jquery.when. This works fine testing on my localhost, but now I need to connect to an api on another server I find I have to add xhrFields: { withCredentials: true }, to all my http requests. Is there any way I can include this in my jquery.get statement, or do I have to convert them all to jquery.ajax statements?

Share Improve this question edited Jan 7, 2020 at 6:09 sideshowbarker 88.2k29 gold badges215 silver badges211 bronze badges asked Jul 24, 2014 at 13:04 user3279063user3279063 351 silver badge4 bronze badges 1
  • 1 Have you had a look at the $.ajaxSetup(); mand - sets up the overall settings for every get / post etc request. Not sure if it covers withCredentials though. – CharlesA Commented Jul 24, 2014 at 13:11
Add a ment  | 

1 Answer 1

Reset to default 18

Try

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

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

发布评论

评论列表(0)

  1. 暂无评论