public
Last active

Trigger.io jQuery adapter to use forge.ajax

  • Download Gist
ajax.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
$.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.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 
$.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();
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.