我从我的 PHP 代码和查询中得到了我需要的东西;除了我真的很难将数据带到前端以填充 HTML 下拉列表。
这是我在 PHP 方面的内容;一切正常
$app->get('/dlteopt', function ($request, $response, $args) {
$which = $_GET['id'];
if ($which) {
if ($which == 'table_1'){
$sql = "SELECT item1 FROM daya.blahblah";
} else if ($which == 'table_2'){
$sql = "SELECT item2 FROM daya.blahblah2";
} else if ($which == 'table_3'){
$sql = "SELECT item3 FROM daya.blahblah3";
}
$stid = oci_parse($this->db, $sql);
$list = array();
while ($list = oci_fetch_array($stid, OCI_ASSOC)) {
$list[] = $list;
var_dump($list); // this outputs the correct array I need, but cant bring it to front correctly into dropdown
}
if (!@oci_execute($stid)) {
$error = oci_error($stid);
throw new Exception($error['message']);
}
oci_execute($stid);
}
这是 jQuery;控制台response日志只是which我随get请求发送的标志 ( ) 变量,它确定通过用户场景查询哪个表。我需要的数组被省略了......
let which = $(frm).attr("id");
$.get('dlteopt', {id: which }, function (response) {
console.log(response); // this just consoles as the $which var no array
$.each(response, function(index, value) {
// started logic to append values in option; but no array or obj found/brought in to iterate through, can handle this part if can get array
});
});
html下拉;只是带有占位符的标准 HTML 选择,直到填充:
<select name='agent' id='agent'><option>Loading...</option></select>
我在这里做错了什么?或丢失/遗忘?
长风秋雁
相关分类