views:

558

answers:

3

hey mates . recently i used jquery auto-complete tag

http://devthought.com/projects/jquery/textboxlist/

everything goes fine except utf-8 tag suggesting , only English tags are suggested

i guess something goes wrong with script lines it works fine with English tags but not with multi byte languages like Persian

+1  A: 

Your HTTP header is wrong. It should be:

header('Content-Type: application/json; charset=UTF-8');

You can also shorten your code and do the sorting with MySQL:

$sql = 'SELECT `tag` FROM `'.$prefix.'_tags` ORDER BY `tag`';
$result = $db->sql_query($sql);
if (!$result) {
    header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
    echo mysql_error();
    exit;
}

$response = array();
$i = 0;
while ($row = $db->sql_fetchrow($result)) {
    $response[] = array($i++, $row);
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($response);
Gumbo
thanks for shortening my code , although ur code doesnt work at all , maybe u didnt know about my sql part . but my problem is not getting persian ( utf-8 ) tags , and only english ones , its so simple how can i did anything wrong ! <input type=\"text\" name='$name' id='$name' size='20' value=\"\" />
farshad Ghazanfari
@farshad Ghazanfari: Where is your tag filtering anyway? Where do you include the user’s input?
Gumbo
i wrote a class for it , and add it to my form , i did not add any filter to tags just read them from sql and ...Can we use different method instead of using json ?
farshad Ghazanfari
@farshad Ghazanfari: I meant your script is just putting all of your tags out as there is no further restriction i.e. no filtering that the tags must begin with a certain sequence (that what the user has already entered).
Gumbo
+1  A: 

Your content-type header is somewhat wrong. First, it should be content-type:something; charset=something, that is, content-type:text/html; charset=utf-8.

But it is actually suggested to use content-type application/json, see here http://stackoverflow.com/questions/477816/the-right-json-content-type

So, you could do it like this

header("Content-Type:application/json; charset=UTF-8");
naivists
hey thanks , i did used that header but nothing worked , then i changed type , uh im tired i can't find the bug
farshad Ghazanfari
+1  A: 

Probably line 212 in the TextboxList.Autocomplete.js is to blame:

regexp = new RegExp('\\b' + escapeRegExp(search), insensitive ? 'i' : '');

That's looking for the given character after a word boundary. But word boundaries are dependent on recognition of word characters, and JavaScript RegExp's list of word characters is just the ASCII alphanumerics plus _. Because RegExp knows nothing about Unicode this won't work where the word begins with a non-ASCII character.

You could try getting rid of the \\b in which case it would match any suggestion with the given string anywhere inside it, not just at the start of words.

bobince
wow , i was going to answer my own question ( just exactly what u said ) and asking how to solve this now , so it will list anything that has that word not the first word , so now how to solve this ?
farshad Ghazanfari
How about something like `'(^|[ !-/:-@[-XXX{-~])'+escapeRegExp(search)`? Note, replace `XXX` with a backquote, I can't type it in comments!
bobince