我有这个代码在独立运行时工作正常(我可以在下拉列表中搜索)
<?php
include_once ("db_connection.php");
$conn = testdb_connect ();
$sth = $conn->prepare('SELECT testCase FROM tooldata ');
$sth->execute();
while($row = $sth->fetch(PDO::FETCH_ASSOC))
{
foreach($row as $key)
{
$var=explode('_', $key);
$feature[] = $var[0];
}
}
$feature = array_intersect_key($feature, array_unique(array_map('strtolower', $feature)));
foreach($feature as $newarr)
{
$newFeature[]=$newarr;
}
?>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link href="../select2-3.4.8/select2.css" rel="stylesheet"/>
<script src="../select2-3.4.8/select2.js"></script>
<script>
$(document).ready(function() { $("#feature").select2(); });
</script>
</head>
<body>
<h2>Select feature</h2>
<form method="get" action="feature.php">
<select name="feature" id="feature">
<?php
?>
<option value > Select Feature</option>
<?php
foreach($newFeature as $feat)
{
?>
<option value="<?php echo $feat;?>"><?php echo $feat;?></option>
<?php
}
?>
</select>
<input type="submit" name="submit" value="Feature">
</body>
</html>
当我在其他php脚本中包含这个脚本时说main.php,当我运行main.php时,我在下拉列表中的搜索不起作用,我在网络选项卡中得到了这个 - 未捕获TypeError:undefined is不是第7行和第37行的功能,分别是 include(“feature_list.php”); 和} 。
可能的原因是什么? 请指导