I have a textbox which has value like “PN & J”.I am storing it in
var sState = $('#txtState').val();
and making Ajax call by
data: 'Service=' + sSvendor + '&City=' + sCity + '&Sub=' + sCitySub + '&State=' + sState + '&Network=' + sNetwork,
But at the receiving end i m retrieving Value as only "PN " it is neglecting string after '&' character. how to overcome this ?
Because
&is the seperator ofkey=valuepairs in a GET request, you need to escape it usingencodeURIComponent;Of note, there’s also
encodeURI, but that doesn’t encode values like&(as it treats the input as a whole URI, rather than a particular component).Feel free to escape the rest of the values yourself for security… I’m just too lazy.