Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Hi all,

i have a full text search on my web page where user type anything and get the result. now i have a problem with apostrophe s in search box. my search request rewrite the URL with the given text in search box and when some one search by O'brain or Mark's it gives error of bad request from the Jquery. i try json.Encode but somehow it is not working.
Posted
Comments
Nelek 20-Aug-14 4:49am    
Maybe if you add some of the code you are trying someone can spot the error.

1 solution

We can escape these kind of characters like single quotes can be escaped using backslashes.
Ex :-
"D'souza" can be written as "D\'sauza".

If the same text is being used in selector text we can use double backslashes to escape the single quote.

Also you can use regular expressions to escape characters to any string having single or double characters as :-

JavaScript
var strReplaced = strToReplace.replace(/(['"])/g, "\\$1");


Hope this will be of help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900