Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to replace all '&' which are in " " in a string....in javascript

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"
like image 903
Aamir Hussain Avatar asked Jan 27 '26 20:01

Aamir Hussain


1 Answers

You must use:

query = encodeURIComponent (query);
like image 65
Bobo Avatar answered Jan 29 '26 10:01

Bobo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!