webster Posted August 12, 2008 Share Posted August 12, 2008 How to use ajax with none english letters like (ċ,á,ä,è,ص,ל,מ,ע,...) I have two pages "test.htm" with the ajax request jscript. When I write english letters, I got them ok. But when I write none english letters I got ? ? I modified the line url=url+"?q="+str to be url=url+"?q="+escape(str) Now I got like this "c%u010B" how can i deal with these characters while date stored in none english letters. Is it clear !!! I tried to use urldecode(); and urlencode() ... is there somthing else ??? test.htm <html><head> <title>ajax test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> var xmlHttp function showResult(str){ if (str.length==0) { document.getElementById("livesearch"). innerHTML=""; document.getElementById("livesearch"). style.border="0px"; return } xmlHttp=GetXmlHttpObject() if (xmlHttp==null){ alert ("Browser does not support HTTP Request") return } var url="test.php" url=url+"?q="+escape(str) url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("livesearch").innerHTML=xmlHttp.responseText; document.getElementById("livesearch"). style.border="1px solid #A5ACB2"; } } function GetXmlHttpObject(){ var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");} } return xmlHttp;} </script> </head> <body> <form> <div class="div1">Live Search</div> <div class="div2"> <input type="text" id="txt1" size="18" onkeyup="showResult(this.value)"> <div id="livesearch"></div> </div></form> </body> </html> test.php <?php print $q=$_GET["q"]; ?> Regards Quote Link to comment Share on other sites More sharing options...
webster Posted August 13, 2008 Author Share Posted August 13, 2008 Is is too hard ??? Quote Link to comment Share on other sites More sharing options...
webster Posted August 14, 2008 Author Share Posted August 14, 2008 I found it here: http://www.php.net/manual/en/function.urldecode.php mkaganer at gmail dot com 04-Dec-2007 02:58 B.H. I had troubles converting Unicode-encoded data in $_GET (like this: %u05D8%u05D1%u05E2) which is generated by JavaScript's escape() function to UTF8 for server-side processing. Finally, i've found a simple solution (only 3 lines of code) that does it (at least in my configuration): <?php function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'UTF-8');; } ?> note that documentation for html_entity_decode() states that "Support for multi-byte character sets was added at PHP 5.0.0" so this might not work for PHP 4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.