Php jquerymobile selectmenu未填充

Php jquerymobile selectmenu未填充,php,json,jquery-mobile,Php,Json,Jquery Mobile,我试图在创建页面时填充所选菜单,但没有显示任何选项 $(document).ready(function() { $.ajax('patientlist.php', function(data){ var html = ''; var len = data.length; for (var i = 0; i< len; i++) { html += '<option value="' + data[i].patient_id + '">'

我试图在创建页面时填充所选菜单,但没有显示任何选项

$(document).ready(function() {
$.ajax('patientlist.php', function(data){
    var html = '';
    var len = data.length;
    for (var i = 0; i< len; i++) {
        html += '<option value="' + data[i].patient_id + '">' + data[i].patient_firstname + data[i].patient_lastname + '</option>';}
    $('#patientselect').append(html);
});
while($row=mysql\u fetch\u assoc($result)){

} 我的结果来自php页面

[{“患者id”:“9”,“患者名”:“亚当”,“患者姓”:“史蒂夫”}]等等

真的很感谢你的帮助,已经坚持了一个星期了

那么,再次发布

首先,您应该将
echo json_encode($data)退出while循环

while($row = mysql_fetch_assoc($result)) {
  $data[] = $row;
}
echo json_encode( $data );
其次,您的
$ajax
语法不正确,请将其更改为
$.post
,并告诉
$.post
请求您期待
patientlist.php的
'json'
响应

$(document).ready(function() {
  $.post('patientlist.php', {}, function(data){
    /* code */
  }, 'json'); // <= set data type json here
});
至少你现在会收到一个有效的请求

注意您的HTML,不要使用
。append
如果它不是DOM元素,您只是将HTML元素构建为字符串,所以请使用

$('#patientselect').html(html);

如果有什么不同的话,我会使用dreamweaver cs5。@Adam更新了帖子,很抱歉,在我第二次编辑之后,一切都被打乱了。我如何向你展示我修改过的代码?对不起,我是Stackoverflow的新手。谢谢!您的代码工作得很好,我只需要添加complete:function(){$('#patientselect').selectmenu('refresh',true);重新生成select菜单。
$(document).ready(function() {
  $.post('patientlist.php', {}, function(data){
    /* code */
  }, 'json'); // <= set data type json here
});
$.each(data, function(index, patient) {
  console.log(patient.patient_id); // or use patient['patient_id']
});
$('#patientselect').html(html);