i am building a query string for my url and need to exclude certain chars from the encode.
I want to exclude the “&” and the “=” so that I can make a statement as such:
first=blah&second=blah and so on….
I guess the best way to put it is how do I stop them from being encoded?
some code:
else if (array[i].nodeName == "SELECT") {
if (array[i].id == "multiple") {
var selected = $.map($('#multiple option:selected'),
function (e) {
return $(e).val();
});
$.each(selected, function (index, value) {
name = array[i].name;
values += app + "\&" + key + "=";
});
} else {
name = arr[i].name;
values = arr[i].value;
}
}
key = encodeURIComponent(name);
value = encodeURIComponent(values);
queryString += name + "=" + values + "&";
No. It’s a builtin function that takes exactly one argument.
You do need to encode
&when it appears in the middle of a key or value so the simplest solution is to encode the individual names and values before combining them. Defineand then call that function for each name/value pair in multiple selects or once for each other checked input.
Using
encodeURIor similar will not properly encode#,=or other necessary code-points.