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-26 01:14:56 +08:00
let token;
2016-09-09 04:58:07 +08:00
export function getToken() {
2016-08-26 01:14:56 +08:00
if (!token) {
token = $('meta[name="csrf-token"]').attr('content');
}
2016-09-09 04:58:07 +08:00
return token;
}
export function ajax(args) {
2016-08-26 01:14:56 +08:00
return new Ember.RSVP.Promise((resolve, reject) => {
2016-09-09 04:58:07 +08:00
args.headers = { 'X-CSRF-Token': getToken() };
2016-08-26 01:14:56 +08:00
args.success = data => Ember.run(null, resolve, data);
args.error = xhr => Ember.run(null, reject, xhr);
args.url = getUrl(args.url);
2016-08-26 01:14:56 +08:00
Ember.$.ajax(args);
});
}