Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Windows Azure, PHP, ...

About the author

Maarten Balliauw is currently employed as .NET Technical Consultant at RealDolmen. His interests are mainly web applications developed in ASP.NET (C#) or PHP and the Windows Azure cloud platform.
More about me More about me
Send mail E-mail me


ASP.NET MVC Quickly Pro NuGet Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn
Maarten Balliauw - MVP - Most Valuable Professional
Maarten Balliauw - ASPInsider

Search

Latest Twitter

    Follow me on Twitter...

    Archive

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright Maarten Balliauw 2012


    JavaScript URI parameter encoding

    When creating a HTTP request in JavaScript, I always used encode() and decode() to pass data between client and server. I also used this approach in PRAjax, my open-source Ajax helper library for PHP.

    A developer working with PRAjax on his site reported to me last week that Swedish characters like å, ä, ö, ... were not passed corerctly to and from the server.

    My first reaction was: add a UTF-8 header on the server side, and it should work. Characters from other character sets are always displayed correctly when doing that. Except when using JavaScript, it seemed when I tried entering Swedish...

    After stepping through my code, I saw everything went wrong after I did encode() on my JavaScript variable. After an hour of different Google searches in the wrong direction, I found out that when using encodeURIComponent() instead of encode(), everything worked fine. It seems like encodeURIComponent() translates more characters than encode().


    Categories: General | Projects
    Comments are closed