Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake ajax understand other acceptable data #4150
Comments
|
Thank you for the issue. However, jQuery automatically processes data to query strings that can be sent in GET requests. This is likely still the most common use case. Besides, changing the defaults of these options would break a lot of code. |
|
Sorry, i fail to see how something like that could break when it don't even work in the first place. I didn't mean you should change the default settings of processData & contentType to false. I only meant that you should check whatever if data is a |
|
The default would have to be changed if you don't want to set |
You shouldn't have to set the request
just setting the content to
Well, the world is changing and i think you are laking behind. It's grate that you try to convert everything to string but not everything can not and should not be casted to a string such as
I think you should. And please don't add something like
I'm not talking for myself, I don't use jQuery any longer but I get that other people do. And I want to help them. The fetch API is not always an option since not even IE11 has the fetch api. Microsoft is still going to support it until 2025 something and other follows this rule and even down to IE9 still today.
Still don't see any breaking changes, it would just be an added functionality? if it is a FormData instance, avoid setting the contentType and don't try to process it to a string - simple, no? I see similar question like this pop up all the time at SO |
|
I wasn't suggesting a core method when I suggested |
|
I'll go ahead and answer this...
No, it would not just be added functionality. You can't always predict how a change like this will affect millions of lines of code in the wild. Would it actually result in breakages? I don't know. We've seen over and over again how behavior changes affected users in ways we never expected. You just have to be extra careful. And this is definitely a change in behavior, which is synonymous with a breaking change when a library has a lot of users. That said, sometimes we deem it necessary and introduce the change in a major version. To me, this doesn't seem critical enough to warrant the change, but the best way to persuade any of the core team is with code. |
ah, My misstake.
IMO it's more like: "Why do they ask this quest?" you don't make it easy for them. just played around with prefilter, where not that easy when you cast an error the first thing that happens. Guess you need to make any core changes to let this slide $.ajaxPrefilter(function( ...args) {
// write a potential fix that never logs anything
console.log(args)
});
$.ajax({
url: '/',
method: 'post',
data: new FormData
})
|
|
You're right, prefilters seem to be applied after the data is converted. The following blocks could perhaps be swapped in ajax.js on line 561. I can't think of a reason why this would be a problem, but I wonder if @gibson042 @jaubourg @dmethvin @mgol @markelog might. // Convert data if not already a string
if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param( s.data, s.traditional );
}
// Apply prefilters
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); |
|
Reopening to investigate the possibility of a prefilter, or at least investigate the possibility of swapping the above blocks of code to enable user prefilters to get at data before it goes to |
|
Thanks |
|
Discussed this in the meeting and we're open to exploring this. First step is to the swap those blocks mentioned above and see if any tests break. |
How to send a file or formdata with jQuery is brought up a lot at StackOverflow
I think you should do things better by trying to understand what kind of data they are sending without having to do
processData = falseandcontentType = falsethat is why i propose this should be possible
What i usually do is propose using the fetch api instead of jquery's ajax, this is something that you don't make any easier for the developers, it's quite the opposite. It makes it harder and more confusing to why things don't work