discourse/app/assets/javascripts/wizard/lib/ajax.js.es6

22 lines
504 B
Plaintext
Raw Normal View History

import getUrl from 'discourse-common/lib/get-url';
2016-08-25 13:14:56 -04:00
let token;
2016-09-08 16:58:07 -04:00
export function getToken() {
2016-08-25 13:14:56 -04:00
if (!token) {
token = $('meta[name="csrf-token"]').attr('content');
}
2016-09-08 16:58:07 -04:00
return token;
}
export function ajax(args) {
2016-08-25 13:14:56 -04:00
return new Ember.RSVP.Promise((resolve, reject) => {
2016-09-08 16:58:07 -04:00
args.headers = { 'X-CSRF-Token': getToken() };
2016-08-25 13:14:56 -04:00
args.success = data => Ember.run(null, resolve, data);
args.error = xhr => Ember.run(null, reject, xhr);
args.url = getUrl(args.url);
2016-08-25 13:14:56 -04:00
Ember.$.ajax(args);
});
}