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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?