Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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
Javascript 使用googleapi和php进行即时搜索_Javascript_Php_Jquery_Database_Google Api - Fatal编程技术网

Javascript 使用googleapi和php进行即时搜索

Javascript 使用googleapi和php进行即时搜索,javascript,php,jquery,database,google-api,Javascript,Php,Jquery,Database,Google Api,我一直在使用google jquery API在PHP中进行即时搜索。 在youtube视频中,该程序正在运行(因为我正在从该视频中学习)。 我的数据库逻辑是正确的,因为我在简单的html页面中尝试了它。 但它不适用于jquery。请给我一些解决这个问题的建议。 我正在ubuntu 14.04上工作 这是我的jquery包含的PHP页面 <!DOCTYPE html> <html> <head> <title>WebPage<

我一直在使用google jquery API在PHP中进行即时搜索。 在youtube视频中,该程序正在运行(因为我正在从该视频中学习)。 我的数据库逻辑是正确的,因为我在简单的html页面中尝试了它。 但它不适用于jquery。请给我一些解决这个问题的建议。 我正在ubuntu 14.04上工作

这是我的jquery包含的PHP页面

<!DOCTYPE html>
<html>
    <head>
    <title>WebPage</title>
    <script type=text/javascript src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type=text/javascript>
    function searchq() {     
            var searchTxt = $("input[name='search']").val();
            $.post('search.php', {search_term: searchTxt}, function(output){
                    $('#output').html(output);
            }); 
    }
    </script>
    </head>
    <body>
    <form action="index.php" method="post">
            <b> First Name: </b> <br/>
            <input type="text" name="search" id="search1" placeholder="Search for members ..." onkeydown="searchq();">
            <br/> <br/> <b> Submit: </b>
            <input type="submit" name="Submit">
    </form>
    <div id="output"></div>
    </body>

网页
函数searchq(){
var searchTxt=$(“输入[name='search']”)val();
$.post('search.php',{search\u term:searchTxt},函数(输出){
$('#output').html(输出);
}); 
}
名字:


提交:

我的日期连接页面如下

<!DOCTYPE html>
<html>
    <head>
    <title>WebPage</title>
    </head>
    <body>
    <?php
            $connection = mysqli_connect("localhost", "root", "password");
            $output = "Search Results. <br/> <br/>";
            if(isset($_POST["search_term"])){
                    $name = $_POST["search_term"];
                    $sql = "SELECT cust_id, last_name, first_name, email FROM widget_corp.customer WHERE first_name LIKE '%"
                            . $name . "%' OR last_name LIKE '%" . $name . "%'";
                    $result = mysqli_query($connection, $sql);
                    $count = mysqli_num_rows($result);
                    if($count == 0){
                            echo "There were no search results.";
                    }
                    else {
                            while($row = mysqli_fetch_assoc($result)){
                                    $firstName = $row["first_name"] . "  ";
                                    $lastName =  $row["last_name"] . "  ";
                                    $Email = $row["email"] ;
                                    $output .= '<div>'.$firstName.' '.$lastName.'</div>';
                            }
                    }
            }
            echo ($output);
    ?>
    </body>

网页

什么意思
不起作用
它是说没有结果,没有提出ajax请求,还是其他什么?在浏览器的开发者工具中观察请求,看看请求会发生什么。就像以前经常被问到和回答的那样,jquery找不到您要定位的元素,因为您的代码在头部,没有准备好文档。将js放在闭合体的正前方tag@chris85DoesNot work(不工作)意味着他们的搜索不可用。@Michael,即使我将标签放在结束正文标签前面,它也不工作。function
searchq
在哪里?