Solved

Problems with passing & (ampersand) back to a webserver using AJAX

Posted on 2009-05-13
3
548 Views
Last Modified: 2012-05-06
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 ??


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&section=' + 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

Open in new window

0
Comment
Question by:bayross
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
geowrian earned 300 total points
ID: 24372113
You need to escape the values:

var addrLine1 = escape("J&K Apts., 2nd Flr") ;
var addrLine2 = escape("S.V road");
var addrLine3 = escape("Mumbai") ;
var cityId = escape("1");
var pincode = escape("400001");
 
objAjaxCompInsertReq.params = 'action=insertCompanyData&section=' + section + "&compId=" + compId +"&addrLine1=" + addrLine1 + "&addrLine2=" + addrLine2 + "&addrLine3=" + addrLine3 + "&cityId=" + cityId + "&pincode=" + pincode +'&SID=' + Math.random() ;

Open in new window

0
 

Author Comment

by:bayross
ID: 24372330
Hi Geowrian,

Thank you for your assistance. I'm obliged.  The solution works just fine.

Regards,

Ivan Bayross
0
 

Author Closing Comment

by:bayross
ID: 31580866
Thank you.  I learned from this.  I'm obliged.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ajax and MVC 2 77
Virtual host in apache 31 90
How to access multiple local hosts from phone on network 5 84
Mysqli_query() & Ajax 2 60
Today I am discussing AJAX problems in IE7 and I bet this will helps many guys out here who have problems with AJAX work. Lets start with the discovery of problem and then we will talk about its different solutions. My last two projects included …
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question