Refactor ajax request
This commit is contained in:
parent
7696b7008f
commit
755414cd7a
2 changed files with 16 additions and 13 deletions
|
@ -1,4 +1,5 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import ajaxRequest from '../../../../utils/ajax-request';
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
apiURL: function() {
|
apiURL: function() {
|
||||||
|
@ -10,19 +11,8 @@ export default Ember.Route.extend({
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
model: function(params) {
|
model: function(params) {
|
||||||
let url = this.get('apiURL') + '/api/' + this.get('genus') + '/users/verify/' + params.nonce;
|
let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
|
||||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
return ajaxRequest(url);
|
||||||
let options = {
|
|
||||||
success: function(data){
|
|
||||||
resolve(data);
|
|
||||||
},
|
|
||||||
error: function(jqXHR, status, error){
|
|
||||||
reject(jqXHR, status, error);
|
|
||||||
},
|
|
||||||
dataType: 'text json',
|
|
||||||
};
|
|
||||||
Ember.$.ajax(url, options);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
13
app/utils/ajax-request.js
Normal file
13
app/utils/ajax-request.js
Normal 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);
|
||||||
|
});
|
||||||
|
}
|
Reference in a new issue