Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AJAX和PHP自动完成(建议列表)_Php_Ajax - Fatal编程技术网

AJAX和PHP自动完成(建议列表)

AJAX和PHP自动完成(建议列表),php,ajax,Php,Ajax,我试图在搜索中显示建议列表,我有4个问题 安全吗 为什么它不能在谷歌chrome和firefox和ie上运行 如果用户 我没有选择任何建议,我已经尝试过了,但是没有选择 没用 [setTimeOut(document.getElementById(“list”).style.display=“无”, (2000年)] 如何在使用WHERE>NAME LIKE时在sql查询中添加引号 这是一段代码 <script type="text/javascript"> function

我试图在搜索中显示
建议列表
,我有4个问题

  • 安全吗

  • 为什么它不能在谷歌chrome和firefox和ie上运行

  • 如果用户 我没有选择任何建议,我已经尝试过了,但是没有选择 没用 [setTimeOut(document.getElementById(“list”).style.display=“无”, (2000年)]

  • 如何在使用WHERE>NAME LIKE时在sql查询中添加引号

  • 这是一段代码

    <script type="text/javascript">
        function showSuggestions(str)
            {
                if(str=="")
                    return;
                if(window.XMLHttpRequest())
                    {
                        xmlhttp = new XMLHttpRequest();
                    }
                else
                    {
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                xmlhttp.onreadystatechange=function()
                    {
                        if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
                            {
                                var c = document.getElementById("list");
                                c.innerHTML = xmlhttp.responseText;
                            }
                    }
                    xmlhttp.open("GET", "/ajax/character/"+str, true);
                    xmlhttp.send();
            }
    </script>
    
    <form action="/characters/" onsubmit="window.location='/characters/'+this.name.value; return false;" class="form" autocomplete="off" method="post">
    <p style="font-weight:200;color:brown;font-size:12px;">Find User.</p>
        <div>Please enter a user name &nbsp;
            <input name="name" type="text" onkeyup="showSuggestions(this.value)" maxlength="35" required="required" pattern="[A-Za-z\s]{3,35}" autofocus="autofocus"/>
            <div id="list"></div>
        </div>
        <p style="text-align:center">
            <input type="submit" class="button" value="Search"/>
        </p>
    </form>
    
    <style>
        .suggestionList {
            margin: 0px;
            padding: 0px;
            padding-left: 10px;
            line-height: 16px;
            list-style: none outside none;
    
        }
    
        .suggestionList li {
    
            margin: 0px 0px 3px 0px;
            padding: 3px;
            cursor: pointer;
        }
    
        .suggestionList li:hover {
            background-color: #659CD8;
        }
    
        .suggestionsBox {
            position: relative;
            left: 230px;
            margin: 10px 0px 0px 0px;
            width: 200px;
            background-color: #212427;
            -moz-border-radius: 7px;
            -webkit-border-radius: 7px;
            border: 2px solid #000; 
            color: #fff;
        }
    </style>
    <?php
        if(isset($_GET['name']) && strlen($_GET['name']) > 1) {
            include('../main.php');
            $name = $_GET['name'];
            if(check_name($name)) {
            ?>
            <div class="suggestionsBox" id="suggestions" style="display :block;">
                <img src="/images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
                <div class="suggestionList" id="SuggestionsList"><?
                    foreach(query('SELECT name FROM users WHERE name LIKE "'.$name.'" LIMIT 5')->fetchAll() as $q) {
                            echo '<a href="/characters/'.$q['name'].'"><li>'.$q['name'].'</li></a>';
                    } ?>
                </div>
            </div>
            <?
        }
        else
            echo 'Invalid name format';
        }
    
    
    功能显示建议(str)
    {
    如果(str==“”)
    返回;
    if(window.XMLHttpRequest())
    {
    xmlhttp=新的XMLHttpRequest();
    }
    其他的
    {
    xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
    }
    xmlhttp.onreadystatechange=函数()
    {
    if(xmlhttp.readyState==4&&xmlhttp.status==200)
    {
    var c=document.getElementById(“列表”);
    c、 innerHTML=xmlhttp.responseText;
    }
    }
    open(“GET”,“/ajax/character/”+str,true);
    xmlhttp.send();
    }
    查找用户

    请输入用户名

    .建议列表{ 边际:0px; 填充:0px; 左侧填充:10px; 线高:16px; 列表样式:无外无; } .建议列表李{ 保证金:0px 0px 3px 0px; 填充:3倍; 光标:指针; } .建议列表李:悬停{ 背景色:#659CD8; } .建议箱{ 位置:相对位置; 左:230像素; 保证金:10px 0px 0px 0px; 宽度:200px; 背景色:#212427; -moz边界半径:7px; -webkit边界半径:7px; 边框:2倍实心#000; 颜色:#fff; }
    点击
    Ctrl+Shift+C
    查看chrome中的
    console
    ,查看是否有任何错误@为我打开元素选项卡的pjp。我总是使用ctrl+alt+j。未捕获类型错误:DOM对象构造函数不能作为函数调用