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
1 Answer
Reset to default 18Try
$.ajaxSetup({xhrFields: { withCredentials: true } });
in your $(document).ready(function() {...});