Created
October 7, 2012 03:21
-
-
Save burgalon/3846989 to your computer and use it in GitHub Desktop.
Trigger.io jQuery adapter to use forge.ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax = (options) -> | |
# console.log 'forge ajax', options | |
dfd = jQuery.Deferred() | |
options.success = (data) -> | |
# console.log "forge ajax resolve", data | |
$(document).trigger 'ajaxStop', [null, options] | |
dfd.resolve data | |
options.error = (error) -> | |
console.log "forge ajax reject", error | |
error.responseText = error.content | |
error.statusText = error.message | |
error.status = parseInt(error.statusCode) | |
$(document).trigger 'ajaxStop', [null, options] | |
# arguments: event, xhr, ajaxSettings, thrownError | |
dfd.reject error | |
$(document).trigger 'ajaxError', error | |
$(document).trigger 'ajaxSend', [null, options] | |
forge.ajax options | |
dfd.promise() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax = function(options) { | |
var dfd; | |
dfd = jQuery.Deferred(); | |
options.success = function(data) { | |
$(document).trigger('ajaxStop', [null, options]); | |
return dfd.resolve(data); | |
}; | |
options.error = function(error) { | |
console.log("forge ajax reject", error); | |
error.responseText = error.content; | |
error.statusText = error.message; | |
error.status = parseInt(error.statusCode); | |
$(document).trigger('ajaxStop', [null, options]); | |
dfd.reject(error); | |
return $(document).trigger('ajaxError', error); | |
}; | |
$(document).trigger('ajaxSend', [null, options]); | |
forge.ajax(options); | |
return dfd.promise(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it