Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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
Owner

Use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.