在制作链式下拉列表时遇到滚动链接的问题

问题描述 投票:1回答:1

我在制作链式下拉时遇到滚动链接问题。

我使用php作为编程语言和codeigniter作为框架,这里是代码

查看代码

     <div class="form-row">
       <div class="col-md-4">
         <label for="inputBody">Body Number</label>
         <select name="inputBody" id="inputBody" class="form-control" required="required">
            <?php foreach ($body as $bd) { ?>
              <option value="<?php echo $bd->bodynumkids ?>" onchange="ambildata('+<?php echo $bd->bodynumkids ?>+');"><?php echo $bd->bodynumkids ?></option>
            <?php } ?>
          </select>
        </div>
        <div class="col-md-6">
           <label for="inputKiddie">Kiddies Name</label>
           <input type="text" name="inputKiddie" id="inputKiddie" class="form-control" placeholder="ex. Super Cop" required="required">
        </div>
        <script type="text/javascript">
           function ambildata(x) {
             $.ajax({
                type:'POST',
                data :'input='+x,
                url :'<?php echo base_url()."Repairpaint/chained" ?>',
                dataType: 'json',
                success: function(data){
                   console.log(data);
                }
               })
              }
          </script>
       </div>

控制器代码

public function chained()
    {
        $dataKiddie = $this->input->post('input');
        $where = array('bodynumkids'=> $dataKiddie);
        $namakiddie = $this->Model_repairpaint->chaincb('kiddiejadi', $where)->result();
        echo json_encode($namakiddie);
    }

结果没有出现在控制台中,只出现了这些警告

This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning; see https://developer.mozilla.org/docs/Mozilla/Performance/ScrollLinkedEffects for further details and to join the discussion on related tools and features!

当我点击下拉列表时,数据库中的数据会出现在控制台中。谁能在这里告诉我解决方案?谢谢你,帮助我。

php codeigniter
1个回答
0
投票

ambildata()function放在<select>标签中而不是在<option>

<select name="inputBody" id="inputBody" class="form-control" required="required" onchange="ambildata(this.value)">

而第二件事是Ajax调用中的一些变化

url : '<?php echo base_url("Repairpaint/chained"); ?>'

要么

url : '<?php echo base_url(); ?>' + 'Repairpaint/chained';

发送数据

data : { 'input': x }
© www.soinside.com 2019 - 2024. All rights reserved.