Although the escape() function was deprecated and replaced by encodeURIComponent, there is an issue with encodeURIComponent as it doesn't encode the single quote/apostrophe character. This poses a problem when trying to escape apostrophes in someone's surname (e.g. 'O'Neill') within an AJAX form. It raises the question of why the ability to improve something was removed.
EDIT:
Here is a code example illustrating the dilemma more clearly. When using the surname 'O'Neill', which includes an apostrophe that requires escaping for URL passing, similar issues arise in other form fields—for example, if entering an address like 'Billy's Tavern'.
<input id='surname' value="O'Neill">
<script>
var get_url = '?surname='+encodeURIComponent($('#surname').val());
$.ajax({
url: get_url
});
</script>
To address this issue, I have devised a custom solution utilizing a separate function. However, the underlying query remains as to why such a custom function is necessary.
<script>
function customEncodeURIComponent(URI) {
return encodeURIComponent(URI).replace(/'/g, "%27");
}
</script>
<input id='surname' value="O'Neill">
<script>
var get_url = '?surname='+customEncodeURIComponent($('#surname').val());
$.ajax({
url: get_url
});
</script>