Skip to main content

Bug Tracker

Side navigation

#11369 closed bug (duplicate)

Opened February 21, 2012 08:48PM UTC

Closed February 21, 2012 08:59PM UTC

Last modified February 22, 2012 03:20PM UTC

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

Reported by: 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:

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

Attachments (0)
Change History (5)

Changed February 21, 2012 08:59PM UTC by dmethvin comment:1

resolution: → duplicate
status: newclosed

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

Changed February 21, 2012 08:59PM UTC by dmethvin comment:2

Duplicate of #3400.

Changed February 21, 2012 11:40PM UTC by dmethvin comment:3

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.

Changed February 22, 2012 02:38AM UTC by comment:4

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.


return s.join( "&" );

whaddya think?

Changed February 22, 2012 03:20PM UTC by dmethvin comment:5

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.