更新的问题: print_r($_POST);
在我在框中键入内容后,在 php 文件输出中。
Array
(
[q] => running
)
打印json_encode($jsonArray);
但是正在打印[]
为绑定参数查询兴趣表的php
$interestValue = $_POST['interestVal']; //////
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $dbh->prepare(
'SELECT interestID, interestVal FROM Interest WHERE interestVal = ?');
$sth->bindParam(1, $interestValue);
$sth->execute();
$jsonArray = array();
while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
$jsonArray[] = array(
'ID' => $result['interestID'],
'Value' => $result['interestVal']);
}
print_r($_POST);
print json_encode($jsonArray); // json encode that array
HTML
<input id="interest" name="interest" value="What are your interests?" />
JS
//Get interests
$(document).ready(function() {
$("input#interest").tokenInput("../../src/php/registration/interest/getInterest.php");
});
框架的JS(http://loopj.com/jquery-tokeninput/)
(function ($) {
// Default settings
var DEFAULT_SETTINGS = {
// Search settings
method: "POST",
contentType: "json",
queryParam: "interestVal",
searchDelay: 300,
minChars: 1,
propertyToSearch: "name",
jsonContainer: null,
// Display settings
hintText: "Type in a search term",
noResultsText: "No results",
searchingText: "Searching...",
deleteText: "×",
animateDropdown: true,
// Tokenization settings
tokenLimit: null,
tokenDelimiter: ",",
preventDuplicates: false,
// Output settings
tokenValue: "name", // orig "id"
}
为什么这个数组是空的??