Solved

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

Posted on 2009-05-13
3
553 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress type image upload 10 47
Does SSL have any bearing on connections via http on port 80? 3 53
When we use cache:false ajax? 1 56
ajax jquery 3 25
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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