我在下面写了一个JS数据的示例部分。我希望它输出" donkeyMan"但它会输出单词" Array"所以我不确定如何抓住那些确切的数据。而魔术建议只是一个引导程序的插件,可以进行下拉。
HTML
<form action="demo.php" method="post">
<input class="form-control" name = "character" id="character">
<button type="submit">SUBMIT</button>
</form>
我在html中的javascript
$('#character').magicSuggest({
placeholder: 'Enter a CharacterName...',
data: [{
name: 'MonkeyMan',
pic: '<img src="tinyIcons/donkeySquare.png">'
}],
valueField: 'name',
valueField: 'pic',
});
简单的PHP代码:
$pp = $_POST["character"];
if (isset($pp)) {echo $pp;}
else
{echo "nothing there";}
答案 0 :(得分:2)
$('#character').magicSuggest({
placeholder: 'Enter a CharacterName...',
data: [{
name: 'MonkeyMan',
pic: '<img src="tinyIcons/donkeySquare.png">'
}],
valueField: 'name'
});
$pp = $_POST["character"];
if(isset($pp)) {
if(is_array($pp)) {
if(isset($pp["name"])) {
echo $pp["name"];
} else {
# just see what's in the array
print_r($pp);
}
} else {
echo $pp;
}
} else {
echo "nothing there";
}