doushou8730
2019-02-14 20:16
浏览 106
已采纳

如何从jquery php中的下拉列表中选择特定选项的ajax调用获取多个数据?

I am working with core php with jquery and ajax. My current scenario is like i am having one select box from database. Onclick of particular select box i want data regarding that select box. and then i have to submit that form too.

I am having one select box :

 <select  id="com_name" name="com_name" >
    <?php   
        foreach($com_data as $key=>$eachdata){
    ?>
    <option value="<?php echo $eachdata['com_id'];?>"  <?php   
            if(isset($_GET['id'])){ echo ($upload['particular_com'] == $eachdata['com_id'])?'selected=selected':'abc';   }    ?> >
        <?php echo $eachdata['com_name']; ?>
    </option>
     <?php }?>
</select>

Above is my dynamic select dropdown with some company names.

Now user will click or change any company name. then below ajax will call:

$("#com_name").on('change',function(){
  var com_id = $(this).val();
  $.ajax({
        method: "GET",
         url:"get_all_employee.php?id="+com_id,
            success:function (data1){
                   $.each(data1, function( index, value ) {

                    });
            },  
    });
});

On above ajax call i will go to another page where i have my query to get all employees.

if(isset($_GET['id'])){
    $explodeVal = $_GET['id'];
    $sql = "select `id`,`com_id`,`employee_name` from employee_info as ei where ei.is_deleted = 1 AND ei.com_id = '".$explodeVal."' ";   
    $execute = mysqli_query($con, $sql);

    return $execute;
}

My query works fine. I am getting all my data with my query. But i dont know to fetch my all records in html form with ajax call.

I already created one input to get data. but dont have any idea about populate multiple data with ajax call into html input box.

<input type="text" name="emp_name" value="">
 <input type="file" name="pay_slip"><br>

How to fetch my records in above input box. and second thing is i want to store files for particular employee into database.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题