Is there a way to dynamically ajax add elements through jquery chosen plugin?

后端 未结 8 1601
南旧
南旧 2020-12-15 06:50

I am trying to use \"Chosen\" plugin by harvest (http://harvesthq.github.com/chosen/) and it works for the static set of options I am passing. However, what I want is that w

8条回答
  •  Happy的楠姐
    2020-12-15 07:01

    You don't need to much stress , keep it simple. You need to add your ajax response in select box html and then update chosen.

    This will look like..

    Code:

    var baseURL='Your Url';
    
     $.ajax({
    
               type: "POST",
    
               url: baseURL+"Your function", //enter path for ajax
    
               data: "id="+id,   //pass any details
    
               success: function(response){   //get response in json_encode()formate
                      
                     var json_data = JSON.parse(response);
    
                      var i=0; var append='';
    
                      if((json_data['catss_data'].length > 0)){
    
                          for(i=0;i < json_data['response_data'].length; i++){
    
                              append+="";
                                       // make response formate in option 
    
                            }
    
                        $('#(selectbox-id)').html(append);   // enter select box id and append data in it
    
                         }
    
                     }
    
               $("#(selectbox-id)").trigger("chosen:updated");  // enter select box id and update chosen
    
       });   
    

提交回复
热议问题