Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11369 closed bug (duplicate)

Why does the param method automatically turn all %20's into +'s ?

Reported by: dan@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


It seems like it should first consult ajaxSettings to find out what the contentType is.

As this is the most 'liked' question for jQuery.param: http://api.jquery.com/jQuery.param/#comment-135895876

It seems like there'd be a justification for this, but I'm not aware of it.

Change History (5)

comment:1 Changed 7 years ago by dmethvin

Resolution: duplicate
Status: newclosed

Explained in #3400, but in case that's a TL;DR:


comment:2 Changed 7 years ago by dmethvin

Duplicate of #3400.

comment:3 Changed 7 years ago by dmethvin

Actually I realized that your question is a bit different. The reason jQuery.param doesn't consult jQuery.ajaxSettings is that those are defaults and don't necessarily relate to the settings being used in any particular request. That is why there is the traditional setting, which causes a mess of code complications in itself.

comment:4 Changed 7 years ago by dan@…

I appreciate the second look.

I was wondering if (and this could be considered a big change API-wise) the contentType could be passed in as a parameter (and set as jQuery.ajaxSettings.contentType if it's undefined [like the 'traditional' parameter]).

The number of places 'param()' is called in jQuery could easily be made to pass this extra parameter.

For the last line of param then it could consult to see if contentType === 'application/x-www-form-urlencoded', if so return the thing it's currently returning.

otherwise, return s.join( "&" );

whaddya think?

comment:5 Changed 7 years ago by dmethvin

What is your particular use case? What are you passing to jQuery.param, what encoding do you need, and what do you do with it once you get it?

I think we've made enough of a mess of jQuery.param already. It tries to accommodate situations like nested objects that can't even occur in an HTML form. If you have a simple case you can probably encode your data with about three lines of code using encodeURIComponent.

Note: See TracTickets for help on using tickets.