mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 05:58:19 +08:00
Convert wizard es6 files to js
This commit is contained in:
24
app/assets/javascripts/wizard/lib/ajax.js
Normal file
24
app/assets/javascripts/wizard/lib/ajax.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { run } from "@ember/runloop";
|
||||
import getUrl from "discourse-common/lib/get-url";
|
||||
import { Promise } from "rsvp";
|
||||
import jQuery from "jquery";
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user