mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 20:05:23 +08:00
25 lines
583 B
JavaScript
25 lines
583 B
JavaScript
import { Promise } from "rsvp";
|
|
import getUrl from "discourse-common/lib/get-url";
|
|
import jQuery from "jquery";
|
|
import { run } from "@ember/runloop";
|
|
|
|
let token;
|
|
|
|
export function getToken() {
|
|
if (!token) {
|
|
token = $('meta[name="csrf-token"]').attr("content");
|
|
}
|
|
|
|
return token;
|
|
}
|
|
|
|
export function ajax(args) {
|
|
return new Promise((resolve, reject) => {
|
|
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);
|
|
});
|
|
}
|