jQuery ajax call to url containing accent character sends bad Uri from IE to server

北慕城南 提交于 2019-12-24 03:07:31

问题


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!


回答1:


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.




回答2:


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(){});
}



回答3:


Just call urldecode on the string :)

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



回答4:


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


来源:https://stackoverflow.com/questions/1597396/jquery-ajax-call-to-url-containing-accent-character-sends-bad-uri-from-ie-to-ser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!