Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.NET AJAX callbacks to web service are becoming very popular and unavoidable these days. The feel that the user gets when only a part of the page is updated without even hindering the UI is the advantage that the callbacks offer. The wait for the…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now