Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@burgalon

burgalon Mar 22, 2013

Use it

Owner

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