JQuery JEditable json select 问题

JQuery JEditable json select issue

我正在使用 JEditable 但在 json select 中我遇到了问题,因为在控制台中显示 json 但在页面中显示 select 输入是空的。

这里是截图:

empty select

console showing the id

json result

这里是代码:

require($_SERVER['DOCUMENT_ROOT'] . '/config.php');
$result = $conn->query("SELECT id_user_details, first_name, last_name
    FROM users");
$return_arr = [];
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
    $return_arr[] = array(
        $row['id_user_details'] => $row['first_name'].' '.$row['last_name'],
    );
};
$conn = null;

header('Content-type: application/json');
echo json_encode($return_arr);

这里是javascript:

$(".status").editable("include/users.php", {
            type   : "select",
            loadurl : "include/select.php",
            submit : "OK",
            submitdata : {pk : $(this).attr('id'), _as_csrf_token: token},
            indicator : '<img src="images/spinner.gif" />',
            style  : "inherit"
        });

select 显示客户端是否需要更改用户

<td>
    <a href="javascrip:void(0);" class="status" id="<?php echo $row['id_ch']; ?>"  style="font-size:11px;">
        <?php echo $row['doctor']; ?>
    </a>
</td>

我终于做到了!

我修改了之前的代码:

require($_SERVER['DOCUMENT_ROOT'] . '/config.php');
$result = $conn->query("SELECT id_user_details, first_name, last_name
    FROM users");
$return_arr = [];
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
    $return_arr[] = array(
        $row['id_user_details'] => $row['first_name'].' '.$row['last_name'],
    );
};
$conn = null;

header('Content-type: application/json');
echo json_encode($return_arr);

给这个:

    require($_SERVER['DOCUMENT_ROOT'] . '/config.php');
$result = $conn->query("SELECT id_user_details, first_name, last_name
    FROM users");
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
        $id_user_details = $row['id_user_details'];
        $array[$id_user_details] = $row['first_name'].' '.$row['last_name'];
};
$conn = null;

header('Content-type: application/json');
print json_encode($array);