views:

424

answers:

4

I was having trouble sending up a url containing accent characters using IE. Here's a simple function:

function runjQueryTest(){
    var url = "/test/Beyoncé/";
    $.get( url, function(){});
}

On the server (PHP) I record the value of the request uri ($_SERVER["REQUEST_URI"]) and I see a difference between what FF/Chrome send up versus what IE sends up.

Chrome and FireFox cause the value of ($_SERVER["REQUEST_URI"]) to be

/test/Beyonc%C3%A9/

but requests from IE 8 show the value of ($_SERVER["REQUEST_URI"]) to be

/test/Beyonc\xe9

This is causing my dispatcher's regular expression handler to not match correctly on the server.

Any ideas what the root issue here is, and how I can fix it for IE?

Thanks!

A: 

I would think you need to manually URLEncode the string. Try this short extension: http://plugins.jquery.com/project/URLEncode

Usage:

alert(  $.URLEncode("This is a \"test\"; or (if you like) an example...");

Output

This%20is%20a%20%22test%22%3B%20or%20%28if%20you%20like%29%20an%20example...
Jasie
+1  A: 

Just call urldecode on the string :)

<?= urldecode("/test/Beyonc\xe9");?>
/test/Beyoncé
Byron Whitlock
`urldecode()` doesn't work for `"/test/Beyonc%C3%A9/"`: http://sandbox.singpolyma.net/php/?php=%3C%3F%3D+urldecode%28%22test%2FBeyonc%25C3%25A9%2F%22%29%3B+%3F%3E
J.F. Sebastian
You might want to reconsider your sandbox. You are wide open for a bad attack. http://sandbox.singpolyma.net/php/?php=%3C%3F%3D+phpinfo()%3B+%3F%3E
Byron Whitlock
+2  A: 

I think the solution to your problem is to url encode the characters prior to using them in your url. This will give you a common base across all the browsers.

oneBelizean
+1  A: 

Without downloading any extension to jquery or use any server-side code, according to w3, you can do:

function runjQueryTest(){
    var url = encodeURI("/test/Beyoncé/");
    $.get( url, function(){});
}
Alex Bagnolini