weixin_33727510 2015-12-11 15:37 采纳率: 0%
浏览 29

准备好选择ajax

I try to use jquery chosen with ajax call : https://harvesthq.github.io/chosen/

My html is :

<div class="form-group m-b logiciel">
    <label>Logiciel concerné</label>
    <select id="logiciel" name="logiciel" class="chosen">
    </select>
</div>

My first script is :

$(document).ready(function () {
    $("#logiciel").load('ajax/ticket_add_select.ajax.php?id=' + $('#client').val());
    $("#logiciel").trigger('chosen:updated');
    $("#logiciel").chosen();
});

And my second one is (#ticket_type is another chosen) :

$(function () {
    $('#client').on('change', function () {
        var id = this.value;
        $("#logiciel").load('ajax/ticket_add_select.ajax.php?id=' + id);
        $("#logiciel").trigger('chosen:updated');
    });
});

Everything works fine when i select something on my first select, but on the first load, the second select is empty. Ajax is ok, i can see the result on log.

Is someone achieve to do something like that ?

  • 写回答

1条回答 默认 最新

  • weixin_33699914 2015-12-11 16:12
    关注

    I'm guessing that you want to run these:

    $("#logiciel").trigger('chosen:updated');
    $("#logiciel").chosen();
    

    After this completes:

    $("#logiciel").load('ajax/ticket_add_select.ajax.php?id=' + $('#client').val());
    

    Because .load() is asynchronous, you have to use the completion handler for the .load() call in order to know when it is done:

    $(document).ready(function () {
        $("#logiciel").load('ajax/ticket_add_select.ajax.php?id=' + $('#client').val(), function() {
            $("#logiciel").trigger('chosen:updated').chosen();
        });
    });
    
    $(document).ready(function () {
        $('#client').on('change', function () {
            var id = this.value;
            $("#logiciel").load('ajax/ticket_add_select.ajax.php?id=' + id, function() {
                $("#logiciel").trigger('chosen:updated');
            });
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作