0

データベースからデータを取得できる非常に単純な ajax 自動提案を作成したいと思います。

ここで見ることができます:

index.php

<html>
<head>
<script type="text/javascript">
function suggest() {
    var txtSearch = document.getElementById('txtSearch').value;

    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject('MicrosoftXMLHTTP');
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('myDiv').innerHTML = xmlhttp.responseText;
        }
    }
    var target = 'include.inc.php?txtSearch=' + txtSearch;
    xmlhttp.open('GET', target, true);
    xmlhttp.send();
}
</script>
</head>
<body>
<input type="text" id="txtSearch" onkeyup="suggest();"/>
<div id="myDiv"></div>
</body>
</html>

incldue.inc.php

<?php

require_once 'connect.inc.php';

if (isset($_GET['txtSearch'])) {
    $txtSearch = $_GET['txtSearch'];
    getSuggest($txtSearch);
}

function getSuggest($text) {

    $sqlCommand = "SELECT `SurName` FROM `person` WHERE `SurName` LIKE '%$text%'";

    $query = mysql_query($sqlCommand);

    $result_count = mysql_num_rows($query);

    while ($row = mysql_fetch_assoc($query)) {
        echo $row['SurName'].'<br />';
    }

?>

問題 :

22行目に次のエラーが表示されますが、理由がわかりません:

Parse error: syntax error, unexpected end of file in C:\wamp\www\PHP_Ajax_Autosuggest\include.inc.php on line 22

PS :

connect.inc.phpコンテンツは問題なく機能するため、内容については言及しませんでした。

どんな助けでも大歓迎です。

4

4 に答える 4

2

getSuggest($text) 関数を適切に閉じていません。?> の前に } を追加するだけです

于 2013-08-10T16:19:58.743 に答える
1

関数を閉じるための右中括弧がありません。それを最後に追加すると、うまくいくはずです。最後の 3 行は次のようになります。

        }
    }
?>
于 2013-08-10T16:18:53.977 に答える