ajax – Typing an accented word in an autocomplete box show other characters – Education Career Blog

Using an ajax autosuggest script that queries a mysql database as I enter names. As I type in a name with an accent, the dropdown shows different characters than the ones I’ve typed in. For example as I type in the last name Hylén, the Ajax dropdown shows Hylén. This occurs if the name is not in the database.

$(document).ready(function(){

$("inputid^='last_'").autocomplete('suggest.php',{

matchCase:true,

formatItem: function(data, i, total)

{

var s=data0.split(",")

return s.join(" "); 

}

});


$("inputid^='last_'").result(function(event, data, formatted){

var ids=this.id.split('_')

var id=ids1; // from last_xx got xxx

var s=html_entity_decode(data0).split(","); // first,middle,last

$(this).next().focus();

$(this).next().select();

//have only last value -- TAB pressed

if(s.length==1)return;

$('#first_'+id).val(s0);

$('#middle_'+id).val(s1);

$('#last_'+id).val(s2);

});

});

What should I be looking at to fix this?

,

I think you should look at your encoding. Looks like “é” is the 2 Unicode bytes of “é” printed as ANSI or whatever. Make sure that you use UTF8 (or UTF16 or whatever charset can handle all your characters) consistently in

  • the database
  • all code files (PHP, Javascript etc)
  • HTTP headers
  • HTML headers

Hope that helps!

Leave a Comment