$("#id_dept").change(function(){
$.ajax({
type: "GET",
url: "GetManager.php",
data: "department=" + $(this).find(":selected").val(),
dataType: "text",
cache: false,
success: function(msg){
$("#manager").empty();
response = $.parseJSON(msg);
for (i = 0; i < response.length; i++) {
$("#manager").append("<option value='" + response[i] + "'>" + response[i] + "</option>");
}
$("#manager").trigger('change');
}}});
$("#id_dept").trigger('change');
});
<tr>
<td><label for="id_dept"><b>Department</label></td>
<td class='centerPad'>:</td>
<td>
<select for="id_dept" name="id_dept" id="id_dept">
<option value=""></option>
<?php
$SQL = "select distinct department from Managers";
$rs = $conn->Execute($SQL);
while (!$rs->EOF) {
$a = $rs->Fields("Department")->value;
echo "<option value='".$a."'>".$a."</option>";
$rs->MoveNext();
}
?>
</select>
</td>
</tr>
<tr>
<td><label for="manager"><b>Approving Manager</label></td>
<td class='centerPad'>:</td>
<td>
<select for="manager" name="managers" id="manager">
<option value=""></option>
</select>
</td>
</tr>
上面的代码是form.php。
[PHP]
$dept = $_GET['department'];
$manager = Array();
// SQL查询返回多个数据库记录。
$query = "SELECT * FROM Managers WHERE Department = '".$dept."'";
$rs = $conn->Execute($query);
while (!$rs->EOF) {
$manager[] = $rs->Fields(1)->value;
$rs->MoveNext();
}
echo json_encode($manager);
[PHP]
上面的代码是Getmanager.php
现在,当我尝试使用我从AJAX获得的值更新我的表时。
$strSQL = "Select * from Managers where Names='".$manager."'";
$rs = $conn->Execute($strSQL);
未捕获的异常&#39; com_exception&#39;消息&#39;来源:未知说明:未知&#39;
这似乎是数据类型的问题。 与&#34; meta http-equiv =&#34; Content-Type&#34;相关的内容含量=&#34; text / html的;字符集= UTF-8&#34;&#34;
请帮助!