bayross
asked on
Problems with passing & (ampersand) back to a webserver using AJAX
We have a d/e form in which a Company Name is being captured.
Often a company name contains a ampersand within it:
eg: Ivan & Sons
This value is being passed to the Webserver for processing there using AJAX.
Hence the POST Query string is being manually constructed using JavaScript and fired back to the WebServer.
It appears that AJAX uses the & character to delimit the NAME:VALUE pairs being sent back to the Web Server (APACHE 2.X) for processing.
The problem encountered is that the VALUE being sent back to the web server is being truncated at the & character.
eg: txtCompanyName:"Ivan & Sons"
What is available in the POST array will be Ivan (only).
This is very puzzling. How is this overcome ??
Often a company name contains a ampersand within it:
eg: Ivan & Sons
This value is being passed to the Webserver for processing there using AJAX.
Hence the POST Query string is being manually constructed using JavaScript and fired back to the WebServer.
It appears that AJAX uses the & character to delimit the NAME:VALUE pairs being sent back to the Web Server (APACHE 2.X) for processing.
The problem encountered is that the VALUE being sent back to the web server is being truncated at the & character.
eg: txtCompanyName:"Ivan & Sons"
What is available in the POST array will be Ivan (only).
This is very puzzling. How is this overcome ??
var addrLine1 = "J&K Apts., 2nd Flr" ;
var addrLine2 = "S.V road";
var addrLine3 = "Mumbai" ;
var cityId = "1";
var pincode = "400001"
objAjaxCompInsertReq.params = 'action=insertCompanyData§ion=' + section + "&compId=" + compId +"&addrLine1=" + addrLine1 + "&addrLine2=" + addrLine2 + "&addrLine3=" + addrLine3 + "&cityId=" + cityId + "&pincode=" + pincode +'&SID=' + Math.random() ;
Notice the ampersand issue in addrLine1.
What is visible in the POST Array is just the alphabet J
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. I learned from this. I'm obliged.
ASKER
Thank you for your assistance. I'm obliged. The solution works just fine.
Regards,
Ivan Bayross