如何模态表单选择选项选择json数据?

时间:2017-09-09 07:41:48

标签: javascript jquery json ajax jsondate

这里我想选择选项 (选择所选的结果) 我的模态形式选择:

<select id="doctor2" name="doctor2">
  <? foreach($staff as $doctor){?>
  <option value="<?=$doctor['staff_id']?>"><?=$doctor['name']?></option>
<?}?> 
</select>

如何选择ajax json数据响应选择选项:

$('.tg-invoices').on('click', '.item-edit', function(){
     var id = $(this).attr('data-id1');

  $.ajax({
    type: 'ajax',
    method: 'get',
    url: '<?=base_url()?>Clinic/editAppointment',
    data: {id: id},
    async: false,
    dataType: 'json',
    success: function(data){

  $("#doctor2 option[value="+data.doctor+"]").attr("selected","selected");

    },
    error: function(){
      alert('Could not Edit Data edit');
    }
  });
});

0 个答案:

没有答案