Skip to content

Instantly share code, notes, and snippets.

@krisselden
Created December 13, 2011 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krisselden/1473687 to your computer and use it in GitHub Desktop.
Save krisselden/1473687 to your computer and use it in GitHub Desktop.
Ember ajax wrapper
App.ajax = (url, settings)->
deferred = $.Deferred()
settings.xhr = ->
xhr = $.ajaxSettings.xhr()
if 'onprogress' of xhr
context = this
xhr.onprogress = (e)->
Ember.run(deferred, deferred.notifyWith, context, [e.loaded/e.total])
xhr
jqXHR = $.ajax(url, settings)
jqXHR.done ->
Ember.run(deferred, deferred.resolveWith, this, arguments)
jqXHR.fail ->
Ember.run(deferred, deferred.rejectWith, this, arguments)
deferred.promise()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment