discourse/app/assets/javascripts/wizard/lib/ajax.js.es6
Robin Ward 8d34f4bbd9 Revert "Revert Ember.run refactors"
This reverts commit fcb1ca52f9.
2019-10-30 09:48:24 -04:00

24 lines
558 B
JavaScript

import { run } from "@ember/runloop";
import getUrl from "discourse-common/lib/get-url";
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 Ember.RSVP.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);
});
}