doukesou4452 2014-03-19 09:39
浏览 61
已采纳

Jquery选择的插件在ajax响应中不起作用

I have two select box. and I want to apply chosen plugin in both select box.

When No-1 Select box change then No-2 select box generate from AJAX response.

Chosen Plugin in No-1 work perfectly. But When No-2 select box generate from ajax then chosen plugin doesn't work in No-2 select box.

main.php

<tr>
   <td>Select Location</td>
   <td>
      <select id="issue_type" name="issue_type" class="chosen-select">
         <option value="" disabled="disabled" selected="selected">Select Location</option>
         <option value="17">RM Store</option>
         <option value="17">PM Store</option>
         <option value="17">FG Store</option>
      </select>
   </td>
</tr>           
<tr id="tr_product" name="product">
   <td>Select Product</td>
   <td></td>
</tr>

JS code for ajax

$('#location').change(function(){
   if(this.value){
      $('#td_avail_qty').html('');
      $.ajax({
         type:"GET",
         url:"mat_issue.php",
         data:{action:"ajax",sub_action:"location",location:this.value}
      }).done(function(data){
         $('tr#tr_product').show().children().eq(1).html(data);
      });
   }
});

mat_issue.php

$product_str = '<select id="product" name="product" class="chosen-select">
                    <option value="" disabled="disabled" selected="selected">Select Product</option>';
$location = $req['location'];
$sql_product =  "SELECT l.`loccode`, l.`stockid`, l.`quantity`,s.description FROM `locstock` l INNER JOIN stockmaster s ON l.stockid = s.stockid WHERE l.`loccode` = '$location'  AND l.`quantity` > 0";

if($query_fg = DB_query($sql_product,$db)):
   while($data_product = DB_fetch_assoc($query_fg)):
      $product_str .= '<option title="Available Quantity '.$data_product['quantity'].'" value="'.$data_product['stockid'].'">'.$data_product['description'].'</option>';
   endwhile;
endif;
$product_str .= '</select>';
echo $product_str;

No-2 Select box generate from ajax successfully. But chosen plugin doesn't work in this select box. enter image description here

I use this code for chosen plugin

var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:"95%"}
}
for (var selector in config) {
      $(selector).chosen(config[selector]);
}

And I use .chosen-select class in my select box

  • 写回答

2条回答 默认 最新

  • dongtong7990 2014-03-19 09:44
    关注

    pass your chosen jquery function in your ajax success function...

    may be this can help you out..

    $('#location').change(function(){
       if(this.value){
          $('#td_avail_qty').html('');
          $.ajax({
             type:"GET",
             url:"mat_issue.php",
             data:{action:"ajax",sub_action:"location",location:this.value}
          }).done(function(data){
             $('tr#tr_product').show().children().eq(1).html(data);
             $("#product").chosen({max_selected_options: 5}); //your chosen code for select tag
          });
       }
    });
    

    let me know if you face any other problem....

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

报告相同问题?

悬赏问题

  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口