Option to prevent encoding by $.ajax and $.param?

Option to prevent encoding by $.ajax and $.param?

This is essentially a proposal for an enhancement to the two named
functions:
I ran into an issue today when sending parameters with the ajax
function. If the data option is set, $.param is used to encode and
format the keys and values into a query string. But some of the
values in my data were already encoded and hence got double encoded.
It was not easy to determine which params had been pre-encoded and
which hadn't. And there's no way to tell $.ajax not to encode the
data because it's already been done.
I got around the issue by explicitly decoding all the params before
passing to $.ajax to be re-encoded. This is obviously ugly and has
the potential for other hidden issues.
I don't know if this happens often enough to do something about it.
But if so, I'm thinking it could be addressed in one of 2 ways. Sorry
for using words instead of code, don't have much time.
1) Add an "encodeData" option to $.ajax and $.param that defaults to
true. $.ajax would pass it through to $.param and If it's false,
it'll skip the encoding step.
$.ajax has plenty of options already and this one wouldn't be used
often I'm sure. But it's trivial to add and backwards compatible.
2) Add an option to pass in a data processing function.
It looks like $.param uses an inner "add" function that does the
simple formatting and encoding. $.ajax could allow passing in a
replacement for that function. It would take the current key and value
being processed and skip encoding or add some special logic based on
the key name.
function newAdd(key, value) {
return key + '=' + value;
}
The only problem with this is that the current add function doesn't
return the formatted string. It accesses an array through a closure
and adds the string explicitly. This could be refactored to use a
binding or something, but it may not be trivial because the
buildParams function also uses this closure to facilitate the
recursion on array values.
Any input is appreciated. If this seems worthwhile I may tackle it
and submit a pull request.
:Marco
--