aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/utils.js')
-rw-r--r--web/src/js/utils.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/web/src/js/utils.js b/web/src/js/utils.js
index 2627cf58..97737b20 100644
--- a/web/src/js/utils.js
+++ b/web/src/js/utils.js
@@ -80,7 +80,7 @@ function getCookie(name) {
var r = document.cookie.match(new RegExp("\\b" + name + "=([^;]*)\\b"));
return r ? r[1] : undefined;
}
-var xsrf = $.param({_xsrf: getCookie("_xsrf")});
+const xsrf = `_xsrf=${getCookie("_xsrf")}`;
//Tornado XSRF Protection.
$.ajaxPrefilter(function (options) {
@@ -101,4 +101,16 @@ $(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) {
console.error(thrownError, message, arguments);
actions.EventLogActions.add_event(thrownError + ": " + message);
alert(message);
-}); \ No newline at end of file
+});
+
+export function fetchApi(url, options) {
+ if(url.indexOf("?") === -1){
+ url += "?" + xsrf;
+ } else {
+ url += "&" + xsrf;
+ }
+ return fetch(url, {
+ ...options,
+ credentials: 'same-origin'
+ });
+} \ No newline at end of file