Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ajax:send event to provide access to jqXHR object for ajax requ…

…ests. Fixes #254.
  • Loading branch information...
commit e4ca2045b202cd7ade97d78c20caa2822c5c28da 1 parent 8100cf3
@JangoSteve JangoSteve authored
Showing with 15 additions and 1 deletion.
  1. +3 −1 src/rails.js
  2. +12 −0 test/public/test/call-remote-callbacks.js
View
4 src/rails.js
@@ -155,7 +155,9 @@
// Only pass url to `ajax` options if not blank
if (url) { options.url = url; }
- return rails.ajax(options);
+ var jqxhr = rails.ajax(options);
+ element.trigger('ajax:send', jqxhr);
+ return jqxhr;
} else {
return false;
}
View
12 test/public/test/call-remote-callbacks.js
@@ -308,4 +308,16 @@ asyncTest('binding to ajax callbacks via .live() triggers handlers properly', 3,
}, 63);
});
+asyncTest('binding to ajax:send event to call jquery methods on ajax object', 2, function() {
+ $('form[data-remote]')
+ .bind('ajax:send', function(e, xhr) {
+ ok(true, 'event should fire');
+ equal(typeof(xhr.abort), 'function', 'event should pass jqXHR object');
+ xhr.abort();
+ })
+ .trigger('submit');
+
+ setTimeout(function() { start(); }, 35);
+});
+
})();
Please sign in to comment.
Something went wrong with that request. Please try again.