【问题标题】:Codeigniter cannot call ajax functionCodeigniter 无法调用 ajax 函数
【发布时间】:2017-03-25 20:50:12
【问题描述】:

我正在尝试使用 ajax 验证注册表单,以检查数据库中用户输入的可用性。我正在使用在教程网站上找到的一些代码,但无法正常工作。

http://www.99points.info/2010/07/codeigniter-tutorial-check-usernameemail-availablity-using-jquer-in-codeigniter/

我正在使用 codeigniter 框架,我的 php 还可以,但我对 jQuery/js 语法知之甚少

查看:

<script>
$(document).ready(function() {
    /// make loader hidden in start
    $('#Loading').hide();    
    $('#email').blur(function()
        {
        var a = $("#email").val();
        var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
        // check if email is valid
        if(filter.test(a))
            {
            // show loader 
            $('#Loading').show();
            $.post("<?php echo base_url()?>signup/check_email_availablity", {
            email: $('#email').val()
            },
            function(response)
                {
                //#emailInfo is a span which will show you message
                $('#Loading').hide();
                setTimeout("finishAjax('Loading', '"+escape(response)+"')", 400);
                });
        return false;
        }
});
function finishAjax(id, response){
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>

所以 ajax 代码什么也没做,我能看到的唯一错误是在 chrome 开发人员工具控制台中出现错误

Uncaught SyntaxError: Unexpected end of input

是不是有些语法错误搞砸了?

我是否缺少一些需要在 codeigniter 中加载的库/帮助程序?

【问题讨论】:

    标签: jquery ajax codeigniter


    【解决方案1】:

    你的问题(至少)在&lt;?php echo base_url()?&gt;

    您忘记了; 并且在关闭 php 标记之前没有空格。

    改为:

    <?php echo base_url(); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      • 2021-09-17
      • 1970-01-01
      相关资源
      最近更新 更多