Javascript JQuery tokeninput:[错误]类型错误:未定义不是对象(正在计算';term.replace';)
我之所以使用,是因为我需要将选择框直接连接到DB 我编写了接受GET请求的PHP脚本,就像在他的GitHub上解释的那样:Javascript JQuery tokeninput:[错误]类型错误:未定义不是对象(正在计算';term.replace';),javascript,php,jquery-tokeninput,Javascript,Php,Jquery Tokeninput,我之所以使用,是因为我需要将选择框直接连接到DB 我编写了接受GET请求的PHP脚本,就像在他的GitHub上解释的那样: <?php require_once('sondaggio.php'); # Connect to the database $s = new Sondaggio(); # Perform the query $query = sprintf("SELECT id, nome from Regioni WHERE nome LIKE '%s%' LIMIT 5", $
<?php
require_once('sondaggio.php');
# Connect to the database
$s = new Sondaggio();
# Perform the query
$query = sprintf("SELECT id, nome from Regioni WHERE nome LIKE '%s%' LIMIT 5", $s->getRealEscapeString($_GET["q"]));
$arr = array();
$arr = $s->readFromDB($query);
# JSON-encode the response
$json_response = json_encode($arr);
# Return the response
echo $json_response;
?>
函数readFromDB($query):
所有这些都经过测试,工作正常,输出符合他的文档要求。但是,当我开始在selectbox中键入时,会出现错误:
[Error] TypeError: undefined is not an object (evaluating 'term.replace')
regexp_escape (jquery.tokeninput.js:828)
find_value_and_highlight_term (jquery.tokeninput.js:844:88)
(anonymous function) (jquery.tokeninput.js:899)
each (jquery.min.js:2:11781)
populateDropdown (jquery.tokeninput.js:896)
success (jquery.tokeninput.js:1031)
o (jquery.min.js:2:14739)
fireWith (jquery.min.js:2:15504)
w (jquery.min.js:4:12484)
d (jquery.min.js:4:18320)
所以我被这个错误困住了,我不知道它为什么会出现,请帮助我。多谢各位
编辑:
var_dump($json_响应)(带有…php?q=t)输出:
解决了,只是个错误。
根据文件:
脚本应以以下格式输出JSON搜索结果:
[
{“id”:“856”,“name”:“House”},
{“id”:“1035”,“姓名”:“绝望主妇”},
...
]
这里的字段是“id”和“name”。
我的查询要求DB输入“id”和“nome”:
$query = sprintf("SELECT id, nome from...
所以我只是更新了查询,如下所示:
$query = sprintf("SELECT id, nome as name from...
现在一切正常 你好,大人物。能否显示
var\u dump($json\u response)的使用输出代码>?更新@Damiandziaduch这就是我的想法;)
string(75) "[{"id":"16","nome":"Toscana\r"},{"id":"17","nome":"Trentino-Alto Adige\r"}]"
$query = sprintf("SELECT id, nome from...
$query = sprintf("SELECT id, nome as name from...