[wd_asp elements=’search’ ratio=’100%’ id=1]

Pass Ampersand using Ajax – Jquery

13th February 2020

Jquery - Variables

jquery icon

Pass Ampersand using Ajax,,When you are passing Jquery variables via Ajax, if the text contains an ampersand (&) it will cut the text at that specific point. it will only pass the text up to it.

Therefore “cat & dog” becomes “cat”. to prevent this from happening you need to add a simple bit of code that should be used in all ajax posts, if you think it will ever contain an ampersand. Which would be 95% of the time.

This will also escape ampersand in urls


myvar = encodeURIComponent(myvar); //pass ampersand

or this example

var output = "dog&cat";
output = encodeURIComponent(output);