The query
part of a URL
seems to consist of key-value pairs separated by &
and associated by =
.
I've taken to always using jQuery's $.param()
function to URL-encode my query strings because I find it makes my code more readable and maintainable.
In the past couple of days I find myself calling the MediaWiki API but when cleaning up my working prototype with hard-coded URLs to use $.param()
I noticed some MediaWiki APIs include query parameters with keys but not values!
Notice the part &redirects
, which takes no value.
jQuery's $.param()
takes an object and since objects consist only of key-value pairs it's not possible to pass an object where one member has a key but no value.
That's fine so I assumed I could just pass some value in such as null
or undefined
or 0
but it seems all of these are treated alike. I find this surprising and I've been unable to spot anything in the MediaWiki API documentation about the reasoning behind this.
OK it's easy to work around in my case by building the URL string manually. My question is "Is this a quirk in the MediaWiki API? Or a quirk in the design of URL-encoding? Where should I read to understand the reasoning behind URL-encoded parameters that have no associated values?