I’ve been working on some code which use Ajax for autocomplete implementing. to accomplish this mission I’ve created :
- Database (unicode_general_ci)
- HTML page which show the results of the autocomplete, encoded as UTF-8 with ‘Content-type: text/html; charset=utf-8’
- PHP file which used to query the Database, also encoded as UTF-8 with ‘Content-type: text/html; charset=utf-8’ and “SET NAMES ‘UTF8′” query to the database.
so.. as it sounds.. all the parts configured well for using UTF-8. so let’s see… in Firefox.. the code is working great, in Internet Explorer, I’m getting the error : “Could not complete the operation due to error c00ce514”, this error indicates that Microsoft XML Parser is having problems when parsing the AJAX response string.
the reasons for this error are :
- the encoding of the requested file
- or the encoding of the sent string…
the first reason could be solved by setting the charset with the header command… the second (which solved my problem..) is to encode the sent string. in my case I sent the string by GET method :
<input name=”autotxt” type=”text” onkeyup=”loadXMLDoc(‘findtxt.php?str=’+this.value)”>
the string that was sent to the “findtxt.php?str=” wasn’t encoded in UTF-8 somehow so… I made a little change of the code like this :
<input name=”autotxt” type=”text” onkeyup=”loadXMLDoc(‘findtxt.php?str=’+encodeURIComponent(this.value))”>
The encodeURIComponent() function encodes a URI component. This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
That’s it, have fun.