Skip to content

Instantly share code, notes, and snippets.

@burgalon
Created October 7, 2012 03:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burgalon/3846989 to your computer and use it in GitHub Desktop.
Save burgalon/3846989 to your computer and use it in GitHub Desktop.
Trigger.io 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
dfd.promise()
$.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();
};
@burgalon
Copy link
Author

Use it

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