JQuery ajax url call containing accent character send bad Uri from IE to server

I'm having trouble sending 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 am writing the value of the request uri ($_SERVER["REQUEST_URI"])

and I can see the difference between what FF / Chrome sends versus what IE sends.

Chrome and FireFox call value ($_SERVER["REQUEST_URI"])

/ test / Beyonc% C3% A9 /

but queries from IE 8 show the value ($_SERVER["REQUEST_URI"])

as

/ test / Beyonc \ xE9

This causes my dispatcher regex engine to not match the server correctly.

Any ideas on what the root problem is and how can I fix it for IE?

Thank!

+2


source to share


4 answers


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



+4


source


Without loading any extension in jquery or using any server side code, according to w3, you can:



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

      

+2


source


Just call urldecode on line :)

<?= urldecode("/test/Beyonc\xe9");?>
/test/Beyoncé

      

+1


source


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

Using:

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...

      

0


source







All Articles