Skip to content

Commit 298f69e

Browse files
committed
Merge branch 'ajaxbefore.data-attr' of https://github.com/ronalchn/jquery-ujs into ronalchn-ajaxbefore.data-attr
2 parents 2e5b8c4 + 8b5c544 commit 298f69e

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/rails.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@
106106

107107
// Submits "remote" forms and links with ajax
108108
handleRemote: function(element) {
109-
var method, url, data,
110-
crossDomain = element.data('cross-domain') || null,
111-
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
112-
options;
109+
var method, url, data, crossDomain, dataType, options;
113110

114111
if (rails.fire(element, 'ajax:before')) {
112+
crossDomain = element.data('cross-domain') || null;
113+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
115114

116115
if (element.is('form')) {
117116
method = element.attr('method');

test/public/test/call-remote-callbacks.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque
4747
});
4848
});
4949

50+
asyncTest('modifying data("type") with "ajax:before" requests new dataType in request', 2, function(){
51+
$('form[data-remote]').data('type','html')
52+
.live('ajax:before', function() {
53+
var form = $(this);
54+
form.data('type','xml')
55+
});
56+
57+
submit(function(form) {
58+
form.bind('ajax:beforeSend', function(e, xhr, settings) {
59+
equal(settings.dataType, 'xml', 'modified dataType should have been requested');
60+
});
61+
});
62+
});
63+
64+
asyncTest('setting data("cross-domain",true) with "ajax:before" uses new setting in request', 2, function(){
65+
$('form[data-remote]').data('cross-domain',false)
66+
.live('ajax:before', function() {
67+
var form = $(this);
68+
form.data('cross-domain',true)
69+
});
70+
71+
submit(function(form) {
72+
form.bind('ajax:beforeSend', function(e, xhr, settings) {
73+
equal(settings.crossDomain, true, 'setting modified in ajax:before should have forced cross-domain request');
74+
});
75+
});
76+
});
77+
5078
asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function() {
5179
submit(function(form) {
5280
form.bind('ajax:beforeSend', function() {

0 commit comments

Comments
 (0)