Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2005, 12:47 PM   PM User | #1
Liberté
New to the CF scene

 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Liberté is an unknown quantity at this point
Javascript escape() function and + symbol

Hi everyone,

I am working on a JSP web application using the Spring framework. I am having trouble with URI encoding for form submission when it comes to the javascript escape() function and the + symbol. The symbol is sent to the server unescaped but when it is decoded by the request object on the server side, the + is converted into a space. So for example, if "C++" is submitted in a form, it is decoded on the server side as "C ".

I am wondering if anyone could give me a suggestion for how to solve this problem. Unfortunately using the encodeURI() function is not an option as we are using iso-8859-1 encoding on the server side (it is an intranet application), and changing the server behaviour is not an option for me at this point. Since encodeURI() encodes in UTF-8 format, I end up with this when I use it instead of escape():

Input: développeur
Output: dã©veloppeur

Thanks in advance for any help you can provide!
Liberté is offline   Reply With Quote
Old 12-28-2005, 12:28 PM   PM User | #2
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
You could pre-convert the + symbols into something else - something you can recognise and feel confident is unique on the other end, for example something like "~~":

Code:
str = str.replace(/(\+\+)/g, '~~');
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
brothercake is offline   Reply With Quote
Old 01-03-2006, 02:45 PM   PM User | #3
Liberté
New to the CF scene

 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Liberté is an unknown quantity at this point
Thank you very much brothercake, your tip was a huge help. I ended up replacing '+' with the ascii code (%2B) and the server side decoded everything properly. I appreciate the help.
Liberté is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:07 PM.


Advertisement
Log in to turn off these ads.