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