jQuery用户界面 - 自动完成 - UTF8字符集 [英] Jquery ui - Autocomplete - UTF8 charset

查看:68
本文介绍了jQuery用户界面 - 自动完成 - UTF8字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM这个jQuery数据录入形式,我需要一个特定的领域与从MySQL数据自动完成有关工作。

im working on this jquery data entry form in which i need a specific field to be autocompleted with data from mysql

我得到的一切工作,自动完成从PHP通过在SQL检索数据
匹配英文/拉丁字符是伟大的。

i got everything working, autocomplete retrieves data from the sql through php matching is great in english/latin characters

问题是,当我键入希腊,我只得到区分大小写的匹配
如果我在正确的情况下键入,让我的比赛和一切顺利,但ID为喜欢它是不区分大小写

problem is, when i type greek, i only get case SENSITIVE matches if i type in the right case, i get my match and everything goes well, but id' like it to be case INsensitive

你明白我使用它与外部来源,所以即时猜测比较两个字符串时,它必须是什么...工程完全正确输入情况下,当...

as you understand i am using it with an external source, so im guessing it must be something when comparing the two strings... works perfectly when typing case correctly...

也,你会在我的code看到我有一个数组[ID,名称]
以我目前的配置,(即使是区分大小写)我搜索的名称,出现在下拉列表中,当我点击我想要的名称,电池被充满了ID,当我提交表单,该ID被发布到下一个PHP页面

also, as you will see in my code i have an array [id,name] with my current configuration, (even case sensitive) i search the name, the dropdown appears, when i click the name i want, the cell gets filled with the ID and when i submit the form, the id gets posted to the next php page.

有没有什么办法让同样的事情,但不是填充字段的ID名称为填补呢?即:?搜索的名称,得到与名称下拉列表中,单击并在现场得到的名字,当我提出我得到的ID发布

is there any way to have exactly the same thing but instead of filling the field with the id to fill it with the name? ie: search for name, get dropdown with names, click and get the name in the field, and when i submit i get the id posted?

任何帮助将大大AP preciated。
这里的code:

any help would be greatly appreciated. here's the code:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="js/dropdowndata/dropdowndata.name.js"></script>

等等等等...

blah blah...

<li class="ui-widget"><label for="name"> Last name: </label><input class="name" name="name" style="width:100px" /></li>

这里的JS:

$(function() {
    var cache = {},
        lastXhr;
    $( ".name" ).autocomplete({
        minLength: 1,
        source: function( request, response ) {
            var term = request.term;
            if ( term in cache ) {
                response( cache[ term ] );
                return;
            }

            lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
                cache[ term ] = data;
                if ( xhr === lastXhr ) {
                    response( data );
                }
            });
        }
    });
});

和这里的源(search.php中):

and here's the source (search.php):

<?php

                $link = mysql_connect("1","2","3");
                        if (!$link) {  die("Database Connection Failed". mysql_error());}

    mysql_set_charset('utf8',$link);

                $db_select = mysql_select_db("form2",$link);
                        if(!$db_select){die("Database Selection Failed " . mysql_error());}

    mysql_query("SET NAMES 'utf8'", $link);

                $result1 = mysql_query("SELECT dlastname,dfirstname,id FROM doctors ORDER BY dlastname ASC", $link);
                        if(!$db_select){die("No Data found in db " . mysql_error());            }

$items=array();

                while($row = mysql_fetch_array($result1)){
                         $items[$row['id']] = $row['dlastname']. ", ". $row['dfirstname'];}

sleep( 1 );
if (empty($_GET['term'])) exit ;
$q = strtolower($_GET["term"]);
if (get_magic_quotes_gpc()) $q = stripslashes($q);



$result = array();
foreach ($items as $value=>$key) {
        if (strpos(strtolower($key),$q ) !== false) {
                array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($value)));
        }
        if (count($result) > 11)
                break;}

echo json_encode($result);


?>

您可以看到我已经包括
        mysql_set_charset('UTF8',$链接);
        的mysql_query(集名称'UTF8',$链接);
在我的源代码PHP文件
在+我的网页的字符集...
甚至试图在源PHP文件设置变量,但它搞砸一切:(

you can see i have included mysql_set_charset('utf8',$link); mysql_query("SET NAMES 'utf8'", $link); in my source php file + the charset in my webpage... even tried setting a tag in the source php file but it messed everything :(


还有任何其他建议/改进将是巨大的,因为这是我的code的第一件之一:)

as you understand i am very new to all these, so if any1 could take some time and explain me what im missing, it would be great :) also any other suggestions/improvements would be great as this is one of my first pieces of code :)

感谢名单提前

推荐答案

我想通了,
似乎有与用strtolower()和UTF-8字符集的一个问题
我换两occurances
    用strtolower($字符串)
在search.php中来:
    mb_strtolower(($字符串),UTF-8)
和它的工作;)

I figured it out, there seems to be a problem with the strtolower() and UTF-8 charset I switched both occurances of strtolower($string) in search.php to: mb_strtolower(($string),'UTF-8') and it worked ;)

在code现在看起来是这样的:

the code looks like this now:

sleep( 1 );
if (empty($_GET['term'])) exit ;
//change in next line:
$q = mb_strtolower(($_GET["term"]),'UTF-8');
if (get_magic_quotes_gpc()) $q = stripslashes($q);



$result = array();
foreach ($items as $value=>$key) {
        //change in next line:
        if (strpos(mb_strtolower(($key),'UTF-8'),$q ) !== false) {
                array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($value)));
        }
        if (count($result) > 11)
                break;}

echo json_encode($result);

thanx的答复家伙:)
这是更清楚我一个上午的心态+咖啡:)

thanx for the replies guys :) it was clearer to me with a morning mindset+ coffee :)

这是任何想法:
还有,你会在我的codeI看到有一个数组[ID,名称]我目前的配置,(即使是区分大小写)我搜索的名字,出现在下拉列表中,当我点击我想要的名字,细胞被充满了ID,当我提交表单,该ID被发布到下一个PHP页面。

any ideas on this: "also, as you will see in my code i have an array [id,name] with my current configuration, (even case sensitive) I search the name, the dropdown appears, when I click the name I want, the cell gets filled with the ID and when I submit the form, the id gets posted to the next PHP page.

有什么办法让同样的事情,但不是填充字段的ID名称为填补呢?即:?搜索的名称,得到与名称下拉列表中,单击并在现场得到的名字,当我提出我得到的ID发布的

Is there any way to have exactly the same thing but instead of filling the field with the id to fill it with the name? ie: search for name, get dropdown with names, click and get the name in the field, and when I submit I get the id posted?"

这篇关于jQuery用户界面 - 自动完成 - UTF8字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆