getAjax helper ... saves a lot of typing, we can extend later

This commit is contained in:
Sam 2013-03-24 23:20:53 -07:00
parent 36d60befbd
commit c2db546877
1 changed files with 27 additions and 0 deletions

View File

@ -53,6 +53,33 @@ Discourse.Model = Ember.Object.extend(Discourse.Presence, {
Discourse.Model.reopenClass({
/**
$.get shortcut that uses Discourse.Url and returns a promise
**/
getAjax: function(url) {
var _this = this;
var promise = new Ember.Deferred();
$.ajax(Discourse.getURL(url), {
cache: false,
type: 'GET',
dataType: 'json',
success: function(result){
promise.resolve(_this.create(result));
},
error: function(jqXHR, textStatus, errorThrown){
promise.reject({
jqXHR: jqXHR,
textStatus: textStatus,
errorThrown: errorThrown
});
}
});
return promise;
},
/**
Given an array of values, return them in a hash