Create a gist now

Instantly share code, notes, and snippets.

What would you like to do? jQuery adapter to use forge.ajax
$.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
$.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]);
return $(document).trigger('ajaxError', error);
$(document).trigger('ajaxSend', [null, options]);
return dfd.promise();

burgalon commented Mar 22, 2013

Use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment