开发者

Typing an accented word in an autocomplete box show other characters

开发者 https://www.devze.com 2023-01-20 13:01 出处:网络
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 a

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

$("input[id^='last_']").autocomplete('suggest.php',{

matchCase:true,

formatItem: function(data, i, total)

{

var s=data[0].split(",")

return s.join(" "); 

}

});


$("input[id^='last_']").result(function(event, data, formatted){

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

var id=ids[1]; // from last_xx got xxx

var s=html_entity_decode(data[0]).split(","); // first,middle,last

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

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

//have only last value -- TAB pressed

if(s.length==1)return;

$('#first_'+id).val(s[0]);

$('#middle_'+id).val(s[1]);

$(开发者_如何学编程'#last_'+id).val(s[2]);

});

});

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消