duangu8264 2017-09-20 05:58
浏览 54
已采纳

Codeigniter中的Ajax不工作

I have the following Script tags in may header.php file. ">

<!-- Bootstrap Core Js -->
<script src="<?php echo  base_url('resource/temp/plugins/bootstrap/js/bootstrap.js'); ?>"></script>

<!-- Select Plugin Js -->
<script src="<?php echo  base_url('resource/temp/plugins/bootstrap-select/js/bootstrap-select.js'); ?>"></script>

<!-- Slimscroll Plugin Js -->
<script src="<?php echo  base_url('resource/temp/plugins/jquery-slimscroll/jquery.slimscroll.js'); ?>"></script>

<!-- Waves Effect Plugin Js -->
<script src="<?php echo  base_url('resource/temp/plugins/node-waves/waves.js'); ?>"></script>

<!-- Jquery CountTo Plugin Js -->
<script src="<?php echo  base_url('resource/temp/plugins/jquery-countto/jquery.countTo.js'); ?>"></script>
<!-- Custom Js -->
<script src="<?php echo  base_url('resource/temp/js/admin.js'); ?>"></script>

<!-- Demo Js -->
<script src="<?php echo  base_url('resource/temp/js/demo.js'); ?>"></script>

and these files are again loaded in the footer file as well along with some other .js files. With all the documents, I cannot call ajax function in one of my pages to populate an option list.

I want to populate a select option list when I click on the other option select field. But its not working. Please help. I tried changing latest jquery.min.js files as well. The min.js file version used in the template is 1.12.4.

Below is my Page where ajax call is used.

<div class="form-group form-float">
                             <div class="form-line">
                            <label>Union</label>
                                <select class="form-control union" name="gunion" id="union"  required >
                                <option value="">-- Please Select--</option>
                                    <?php
                                    foreach($union as $row)
                                    {
                                    ?>
                                    <option value="<?php echo $row->u_name;?>"><?php echo $row->u_name;?></option>
                                    <?php
                                    }
                                    ?>
                               </select>
                                 <span class="text-danger"> <?php echo form_error('tonque'); ?></span>     
                                 </div>

                                  <div class="form-line">
                            <label>Sakha</label>
                                <select class="form-control" name="gshaka" id="sakha" required>
                                <option value="">---Please Select--</option>

                               </select>
                                 <span class="text-danger"> <?php echo form_error('tonque'); ?></span>     
                                 </div>

and the Script:

         <script type="javascript">
  $(document).ready(function(){
   $('#union').on('change',function(){
    var unionID = $(this).val(); 
    console.log(unionID);
    if(unionID){
        $.ajax({
            type:'POST',
            url:'getsakha/'+unionID,
            cache:false,
            success:function(html){
                $('#sakha').html(html);
                    }
        }); 
        }else{
        $('#sakha').html('<option value="">Select Union first</option>');
 }
   });
 });
</script>
  • 写回答

2条回答 默认 最新

  • duanjia2772 2017-09-20 06:12
    关注

    Remove javascript from script tag of type attribute

    <script type="javascript">

    add type="text/javascript" in your script tag

    <script type="text/javascript">

    OR either remove type attribute

    <script>

    This happens because there are not type attribute of javascript but there is text/javascript. If you are not writing type attribute then it will consider as a javascript

    I hope this may help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器