在进行链接下拉菜单时面临滚动链接的麻烦

时间:2019-04-09 06:02:33

标签: php codeigniter

在进行链接下拉菜单时,我面临着滚动链接的麻烦。

我正在使用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!

当我单击下拉列表时,期望来自数据库的数据出现在控制台中。有人可以告诉我解决方案吗?之前感谢您对我的帮助。

1 个答案:

答案 0 :(得分:0)

ambildata()标签中放置<select>功能不在<option>

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

第二件事是Ajax调用发生了变化

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

OR

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

发送数据

data : { 'input': x }