简体   繁体   English

如何为选定的下拉值ajax加载所有匹配的数据行

[英]how to load all matching data row for selected dropdown values ajax

i have dropdown boxes for user_id and er and once both selected i want to load all the data as rows. 我有user_id和er的下拉框,并且都选择了后,我想将所有数据加载为行。 please advice. 请指教。

below is my controller 下面是我的控制器

$getShifts = Shifts::Where('user_id','=',$user_id)->Where('week_id','=',$week)->get();

how can i proceed 我该如何进行

table

   <table class="table table-hover">
                                    <tr class="table-header">
                                        <th>Day</th>
                                        <th>Date</th>
                                        <th>Start</th>
                                        <th>End</th>
                                        <th>Total
                                            <br/> Hours
                                        </th>
                                        <th>Run
                                            <br/> Type
                                        </th>
                                        <th>Edit
                                            <br/> / Delete
                                        </th>
                                    </tr>

EDIT plese check below code which i have tried 编辑请检查下面我尝试过的代码

               success: function(data) {
                    var json_obj = $.parseJSON(data);//parse JSON

                    var output="<tr>";
                    for (var i in json_obj)
                    {

                        output+=
                                "<td>" +  json_obj[i].id + "</td>"+
                                "<td>" +  json_obj[i].bus_no + "</td>"+
                                "<td>" +  json_obj[i].shift_no + "</td>"

                        ;

                    }
                    output+="</tr>";

                    $('#span').html(output);

                }

You should call your controller function in ajax and in controller you will get the selected data, so based on that run required query. 您应该在ajax中调用控制器函数,然后在控制器中将获取选定的数据,因此将基于运行所需的查询。

$(document).ready(function() {
    $("#combo, #user_id").change(function(){

       var combo = $('#combo option:selected').val();    
       var user_id = $('#user_id option:selected').val();   
       if(combo && user_id) { 
            $.ajax({
                url: "path to controller function",
                type: "POST",
                dataType: "HTML",
                async: false,
                data:{combo:combo.user_id:user_id},
                success: function(data) {
                      alert(data)   // here you ll see the data from controllen, you can manipulate according to your requirement.               
                }
          }); 
        }

     });
});

in controller 在控制器中

echo "
   <tr>
       <td>$day</td>
       <td>$date</td>
       <td>$start</td>
       <td>$end</td>
       <td>$end</td>
       <td>$end</td>
   </tr>  ";

manipulate all fields in to a tr in controller and in ajax success() append the data to table. 在控制器中处理tr中的所有字段,并在ajax success()中将数据追加到表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM