Refactor ajax request

This commit is contained in:
Matthew Dillon 2015-07-15 19:52:05 -08:00
parent 7696b7008f
commit 755414cd7a
2 changed files with 16 additions and 13 deletions

View file

@ -1,4 +1,5 @@
import Ember from 'ember';
import ajaxRequest from '../../../../utils/ajax-request';
export default Ember.Route.extend({
apiURL: function() {
@ -10,19 +11,8 @@ export default Ember.Route.extend({
}.property(),
model: function(params) {
let url = this.get('apiURL') + '/api/' + this.get('genus') + '/users/verify/' + params.nonce;
return new Ember.RSVP.Promise(function(resolve, reject) {
let options = {
success: function(data){
resolve(data);
},
error: function(jqXHR, status, error){
reject(jqXHR, status, error);
},
dataType: 'text json',
};
Ember.$.ajax(url, options);
});
let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
return ajaxRequest(url);
},

13
app/utils/ajax-request.js Normal file
View file

@ -0,0 +1,13 @@
export default function ajaxRequest(url, options) {
return new Ember.RSVP.Promise(function(resolve, reject) {
options = options || {};
options.url = url;
options.success = function(data) {
resolve(data);
};
options.error = function(jqXHR, status, error) {
reject(jqXHR, status, error);
};
Ember.$.ajax(options);
});
}