discourse/app/assets/javascripts/wizard/lib/ajax.js

Failed to ignore revisions in .git-blame-ignore-revs.

25 lines
579 B
JavaScript
Raw Normal View History

import { run } from "@ember/runloop";
2018-06-15 23:03:24 +08:00
import getUrl from "discourse-common/lib/get-url";
import { Promise } from "rsvp";
import jQuery from "jquery";
2016-08-26 01:14:56 +08:00
let token;
2016-09-09 04:58:07 +08:00
export function getToken() {
2016-08-26 01:14:56 +08:00
if (!token) {
2018-06-15 23:03:24 +08:00
token = $('meta[name="csrf-token"]').attr("content");
2016-08-26 01:14:56 +08:00
}
2016-09-09 04:58:07 +08:00
return token;
}
export function ajax(args) {
return new Promise((resolve, reject) => {
2018-06-15 23:03:24 +08:00
args.headers = { "X-CSRF-Token": getToken() };
args.success = data => run(null, resolve, data);
args.error = xhr => run(null, reject, xhr);
args.url = getUrl(args.url);
jQuery.ajax(args);
2016-08-26 01:14:56 +08:00
});
}