普通网友 2014-08-27 13:06
浏览 15

Ajax无法启动

Im trying to setup, an ajax autocomplete , but its unable to fire don't know what im really doing wrong, please take a look at my code, this is my whole script by the way the autocomple function is at the bottom.

<script type="text/javascript">

$(function(){
    $('#type').change(function(){
        $.ajax({    url: '<?php echo $this->baseUrl()?>/admin/ajax/add-form/type/' + encodeURIComponent($('#type').val()),
                    dataType: 'json',
                    success: function(data)
                    {
                        $("#more").html(data.form);
                        if ($('#type').val() == 'monthly')
                        {   
                            yearchange();
                        }
                        if ($('#type').val() == 'quarterly')
                        {   
                            quarterlyyearchange();
                        }
                    }       
                });
    });
});

    function yearchange()
    {
            $('#year').change(function(){
                $.ajax({    url: '<?php echo $this->baseUrl()?>/admin/ajax/excel-monthly/year/' + encodeURIComponent($('#year').val()),
                dataType: 'json',
                    success: function(data)
                    {
                        $("#more").html(data.form);
                        yearchange();
                    }       
                });
            });
    }

    function quarterlyyearchange()
    {
            $('#quarterlyyear').change(function(){
                $.ajax({    url: '<?php echo $this->baseUrl()?>/admin/ajax/excel-quarterly/year/' + encodeURIComponent($('#quarterlyyear').val()),
                dataType: 'json',
                    success: function(data)
                    {
                        $("#more").html(data.form);
                        quarterlyyearchange();
                    }       
                });
            });
    }

        function sicchange()
    {
            $('#search').change(function(){
                $.ajax({    url: '<?php echo $this->baseUrl()?>/admin/ajax/excel-sic/search/' + encodeURIComponent($('#quarterlyyear').val()),
                dataType: 'json',
                    success: function(data)
                    {
                        $("#more").html(data.form);
                        sicchange();
                    }       
                });
            });
    }

    /*********************************Add Autocomplete*******************************************/
    function addac()
    {
        $( "#search" ).autocomplete({
            minLength: 2,
            dataType: 'JSON',
            source: function(request, response)
            {
                    $.ajax({    url: '<?php echo $this->baseUrl()?>/admin/ajax/ac-sic/phrase/' + request.term,
                                dataType: 'json',
                                success: function(data)
                                {
                                    response(data);
                                }
                                })
                          }

                          });
    }

</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿