0

I'm facing a strange problem with escaping a single quote through an xml parser:

var strCallUrl = contextPath + "Controller?formfilter=registration&selectedUserType="+userType+"&emailID="+advisorEmail;
strCallUrl = strCallUrl.replace(/'/g, "\'");
alert(strCallUrl);
var objSeamlessRegLoad = new JKL.ParseXML.Text(strCallUrl,'','POST');

when I hit the last line, it doesn't go forward because of the singlequote inserted in email address(var advisorEmail), without single quote in that variable, it works absolutely fine. Is it possible to escape the single quote through JKL.ParseXML.Text()?

I have already tried "\'" and also tried escape(strCallUrl), none of these seem to work.

Keethan
  • 43
  • 1
  • 7

1 Answers1

0

Using escape would work, but you are applying it to the entire URL, which would also encode everything in the URL that shouldn't be encoded.

Use it on the value only, and use the encodeURIComponent method instead (Best practice: escape, or encodeURI / encodeURIComponent):

var strCallUrl = contextPath + "Controller?formfilter=registration&selectedUserType="+userType+"&emailID="+encodeURIComponent(advisorEmail);
alert(strCallUrl);
var objSeamlessRegLoad = new JKL.ParseXML.Text(strCallUrl,'','POST');
Community
  • 1
  • 1
Guffa
  • 687,336
  • 108
  • 737
  • 1,005