Do not use the “JavaScript String replace() Method”. It will replace the first occurrence of the special characters. If you have 2 occurance of the same special characters in the filtering parameter, it will fail. So use the regular expression to replace the characters.
function replaceSpecialCharacters(attribute) {
// replace the single quotes
attribute = attribute.replace(/'/g, "''");
attribute = attribute.replace(/%/g, "%25");
attribute = attribute.replace(/\+/g, "%2B");
attribute = attribute.replace(/\//g, "%2F");
attribute = attribute.replace(/\?/g, "%3F");
attribute = attribute.replace(/#/g, "%23");
attribute = attribute.replace(/&/g, "%26");
return attribute;
}
Also pay attention, since the replacements also contains %
then %
itself should be replaced at the beginning