-
Notifications
You must be signed in to change notification settings - Fork 505
Fix for broken cross domain behaviour in jQuery >= 1.5 #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,7 @@ | |
| // Submits "remote" forms and links with ajax | ||
| handleRemote: function(element) { | ||
| var method, url, data, | ||
| crossDomain = element.data('cross-domain') || false, | ||
| dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType); | ||
|
|
||
| if (rails.fire(element, 'ajax:before')) { | ||
|
|
@@ -116,7 +117,7 @@ | |
| } | ||
|
|
||
| rails.ajax({ | ||
| url: url, type: method || 'GET', data: data, dataType: dataType, | ||
| url: url, type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be noted that the I read through the jquery source, since it's not really documented anywhere, but among other things, setting According to the comments in the jquery source: |
||
| // stopping the "ajax:beforeSend" event will cancel the ajax request | ||
| beforeSend: function(xhr, settings) { | ||
| if (settings.dataType === undefined) { | ||
|
|
@@ -244,7 +245,7 @@ | |
|
|
||
| // ajaxPrefilter is a jQuery 1.5 feature | ||
| if ('ajaxPrefilter' in $) { | ||
| $.ajaxPrefilter(function(options, originalOptions, xhr){ rails.CSRFProtection(xhr); }); | ||
| $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); | ||
| } else { | ||
| $(document).ajaxSend(function(e, xhr){ rails.CSRFProtection(xhr); }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also reading through jquery source, I found that jquery does try to intelligently guess whether or not crossDomain should be enabled based on the request URL and the current URL, just as I had previously suggested. See these lines in ajax.js.
Because of this, rather than defaulting
crossDomainto false, we should instead default it tonullso jquery can do it's thing.