簡體   English   中英

AJAX:Bootstrap Typeahead:意外的令牌錯誤

[英]AJAX: Bootstrap Typeahead: Unexpected Token Error

我在文檔中的第一個字母上出現意外的令牌錯誤。

$('#typeahead').typeahead({
source: function (typeahead, query) {
    return $.post('ajax/page.php', { query: query }, function (data) {
        alert(data);
        return typeahead.process(JSON.parse(data));
    });
}
});

在我的page.php中:

<?php 
        $array[] = array("test","treat","food");
        $json = json_encode($array);
        echo "<script>var query = ".$json.";</script>";
?>

因此,使用此代碼,我會收到Uncaught Syntax: Unexpected token <的錯誤

所以當我刪除<script></script> ,它只會echo "var query=".$json.";" ,我得到Uncaught Syntax: Unexpected token v

所以我假設它只是繼續給我一個意外的標記,即第一個字母正在回顯於page.php

誰能告訴我有什么問題?

謝謝!

$('#typeahead').typeahead({
source: function (query, process) {
    return $.post('ajax/page.php', { query: query }, function (data) {
        process(JSON.parse(data));
    });
}
});

//page.php
$array = array("test","treat","food");
echo json_encode($array);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM