I have url in which the parameters contain ‘&’ characters ..now i have to do an ajax call but the server sends exception on that..so the solution is to replace the ‘&’ of parameters by %26 and then make the call…
e.g…
url = http://localhost.com/?q=java&industry="IT&web"&location="New-york & Florida"
The result must be…
= http://localhost.com/?q=java&industry="IT%26web"&location="New-york %26 Florida"
If you’re stuck with this string and want to try to encode it:
One option is to capture all quoted expressions (assuming they match, of course), and apply
encodeURIComponenton them. The result is having the whole parameter encoded, including the quotes:Similarly, you can replace only the ampersands if that’s what you need:
In both cases, this may clash with already-escaped characters, so again, the best solution is to fix the problem at its source, where the url is created.