2019-02-14 20:16
浏览 105

如何从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" >
        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']; ?>
     <?php }?>

Above is my dynamic select dropdown with some company names.

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

  var com_id = $(this).val();
        method: "GET",
            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.

    $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条回答 默认 最新

  • dongxian7471 2019-02-14 23:20

    Hi you should do it like this:

    do a function like this

    function ajaxList(id){
      return   $.ajax({
        method: "POST",
        url: "../employees.php",
        data: {  id: id}

    then call it like this:

        if (id != '')//
                       .done(function( response ) {
                                                var data=JSON.parse(response);
                                                if (data != null) {
                                                    jQuery.each(data, function(index, value){
    $("#cmbEmployee").append('<option value=' + '>' + '</option>');

    Hope it helps

    打赏 评论

相关推荐 更多相似问题