Solved

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

Posted on 2009-05-13
3
564 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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