-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Ajax: Support binary data (including FormData) #5197
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import jQuery from "../core.js"; | ||
|
|
||
| import "../ajax.js"; | ||
|
|
||
| jQuery.ajaxPrefilter( function( s ) { | ||
|
|
||
| // Binary data needs to be passed to XHR as-is without stringification. | ||
| if ( typeof s.data !== "string" && !jQuery.isPlainObject( s.data ) ) { | ||
| s.processData = false; | ||
| } | ||
|
|
||
| // `Content-Type` for requests with `FormData` bodies needs to be set | ||
| // by the browser as it needs to append the `boundary` it generated. | ||
| if ( s.data instanceof window.FormData ) { | ||
| s.contentType = false; | ||
|
Member
Author
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. Note to self: check if this could be overridden in options if this is set to
Member
Author
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. OK, this cannot be changed via settings as of now. 😕 I'll need another patch, I think.
Member
Author
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. PR: #5205 |
||
| } | ||
| } ); | ||
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.
I think moving prefilters ahead of string coercion is a breaking change with respect to custom prefilters, cf. https://api.jquery.com/jQuery.ajaxPrefilter/ (emphasis mine):
Is there a way to instead establish something like prefilter phases?
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.
The line that now happens after the prefilters is only setting
data, not options. Is there any change that I'm missing?BTW, I would also consider this a breaking change regardless of the above, that's why I'm targeting it at v4.