dongmi4927 2018-05-16 12:37
浏览 129
已采纳

将json数组更新为数据自动完成后,它不会更新data-autocomplete的值

I am creating a dynamic form for a hospital. Here i have a problem with data-autocomplete. The problem is after updating json array to data-autocomplete=' ' it is not updating the value of data-autocomplete=' '. AS I am using html(bootstrap) and php templete for my frontend forms so,all links are properly arrenged and one input element similar to this is working fine but i have updated the values using php for that input.

Html code

<input type='text' class="form-control ui-autocomplete-input" data-autocomplete='' autocomplete="off" id="patient_type_desc" name="patient_type_desc" class="form-control" />

JQuery Code

$.post(url, {"referral":referral}, function(data){
   //console.log(data);
   $('#patient_type_desc').attr('data-autocomplete', data);
});

This code is updating the value, but in form autocomplete is not populating with suggestions.

The data variable is like below

["name1","name2"]

I tried with this jQuery code also but no use - This code not at all working

$( "#patient_type_desc" ).autocomplete({
  source: data
});
  • 写回答

2条回答 默认 最新

  • doulu4976 2018-05-17 05:24
    关注

    My Jquery is like this now

    $.post(url, {"referral":referral}, function(data){
                    //console.log(data);
                    $( "#patient_type_desc" ).autocomplete({
                        source: data
                    });
                        //$('#patient_type_desc').attr('data-autocomplete', data);
                    }, "json");
    

    Finally working by adding "json". Thank you for all bro's.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU