?
Solved

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

Posted on 2009-05-13
3
Medium Priority
?
570 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 1200 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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