mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 18:58:34 +08:00
519528daa2
- inlines dasherize helper in sk - uses an ajax helper to load wizard's ajax lib when in wizard - amends wizard's ajax lib to work with string as first arg - disabled loading spinner in wizard as it's not available
34 lines
707 B
JavaScript
34 lines
707 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) {
|
|
let url;
|
|
|
|
if (arguments.length === 2) {
|
|
url = arguments[0];
|
|
args = arguments[1];
|
|
} else {
|
|
url = args.url;
|
|
}
|
|
|
|
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(url);
|
|
jQuery.ajax(args);
|
|
});
|
|
}
|