Skip to content

Instantly share code, notes, and snippets.

@barmatz
Created September 21, 2015 18:52
Show Gist options
  • Select an option

  • Save barmatz/0c53d2e4961560c81ae0 to your computer and use it in GitHub Desktop.

Select an option

Save barmatz/0c53d2e4961560c81ae0 to your computer and use it in GitHub Desktop.
JavaScript XHR promise wrapper for Ember
function request(method, url, data) {
var defferred, xhr;
if (!data) {
data = {};
}
defferred = new Ember.RSVP.Promise(function (resolve, reject) {
xhr = Ember.$.ajax({
method: method,
url: url,
data: data,
contentType: 'application/json'
})
.then(resolve)
.fail(function (err) {
reject(err);
});
});
return defferred;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment