Set data in Select2 after insert with AJAX

后端 未结 2 638
我在风中等你
我在风中等你 2021-02-05 18:29

i\'m using the Select2 with AJAX (the code below):

$(\".select2-ajax\").select2({
        placeholder: \"Search user\",
        minimumInputLength: 1,
        aj         


        
2条回答
  •  你的背包
    2021-02-05 18:43

    I managed to make it work. After POST in jQuery, i get a JSON with the new data and set the hidden input and the select ('.select2-ajax')

    $('#client=id').val(data.id);
    $('#modal-solicitante').modal('hide'); //This is my
    $(".select2-ajax").select2('data', {id: data.id, name: data.name, email: data.email});
    

提交回复
热议问题