Utf-8 problem in using jquery autocomplete tags

Hey comrades. I recently used jQuery auto-complete tag

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

everything is going fine, except for the proposed utf-8 tag, only English tags are offered

I think something is wrong with the lines of the script, it works fine with English tags, but not with a few byte languages ​​like Persian

+3
source share
4 answers

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

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

. , JavaScript RegExp - - ASCII _. RegExp Unicode, , , ASCII.

\\b, ​​ , .

+3

HTTP- . :

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

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);
+1

. -, content-type:something; charset=something, content-type:text/html; charset=utf-8.

- application/json, . JSON?

, ,

header("Content-Type:application/json; charset=UTF-8");
+1
source

Probably line 215 in TextboxList.Autocomplete.js is to blame:

if (regexp.test(values[i][1])) newvals.push(values[i]);

hides him up

if (values[i][1].indexOf(escapeRegExp(search)) != -1) newvals.push(values[i]);

Bobins (first answer) is correct, the problem is on line 212, but it can be resolved on line 215

+1
source

Source: https://habr.com/ru/post/1729769/


All Articles