1

I'm trying to validate a sign up form using ajax to check the availability of user input in a database. I'm using some code I found on a tutorial site but can't get it to work.

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

I'm using codeigniter framework, my php is ok but I know little of jQuery/js syntax

View:

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

So the ajax code does nothing the only thing I can see that's amiss is in the chrome developer tools console giving an error

Uncaught SyntaxError: Unexpected end of input

Is there some syntax error messing it up?

Am I missing some library/helper that I need to load in codeigniter?

1 Answer 1

1

Your problem (at least) is in the <?php echo base_url()?>

You forgot ; and no space before closing php tag.

change to :

<?php echo base_url(); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.