discourse/app/assets/javascripts/wizard/lib/ajax.js.es6
Robin Ward 9347108f02 Support for importing jQuery
Also remove Ember.Qunit error about Ember.$ for now
2019-10-23 13:25:25 -04:00

23 lines
532 B
JavaScript

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 => Ember.run(null, resolve, data);
args.error = xhr => Ember.run(null, reject, xhr);
args.url = getUrl(args.url);
jQuery.ajax(args);
});
}