Reputation: 1
I am doing a username availablity on blur using jquery ajax
respose is Available getting in firebug
My problem is the loading image is keep on rotating.
ReferenceError in firebug console: finishAjax is not defined
setTimeout("finishAjax('Info', '"+escape(response)+"')", 450); Here's it
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<link href="css.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function check_username() {
$.post("check_username_availablity.php", {
username: $('#name').val(),
}, function(response){
//$('#Info').fadeOut();
//$('#Loading').hide();
setTimeout("finishAjax('Info', '"+escape(response)+"')", 450);
});
function finishAjax(id, response) {
$('#'+id).html(unescape(response));
//$('#'+id).fadeIn(1000);
}
}
</script>
</head>
<?php
include('dbcon.php');?>
<body>
<form action="#" name="customForm" id="customForm" method="post" enctype="multipart/form-data">
<div class="both">
<h4> Try "Zeeshan" , "John" , "Katty", "Jimmy" </h4><br clear="all" /><br clear="all" />
<br clear="all" />
<div>
<label>User Name</label>
<input id="name" name="username" type="text" value="" onblur="check_username()"/>
<div id="Info"></div>
<span id="Loading"><img src="loader.gif" alt="" /></span>
</div>
</div>
</form>
</body>
</html>
<?php
include('dbcon.php');
if($_REQUEST)
{
$username = $_REQUEST['username'];
$query = "select * from register where username = '".strtolower($username)."'";
$results = mysql_query( $query) or die('ok');
if(mysql_num_rows(@$results) > 0) // not available
{
echo '<div id="Error">Already Taken</div>';
}
else
{
echo '<div id="Success">Available</div>';
}
}?>
Thanks..
Upvotes: 0
Views: 1142
Reputation: 148110
You need to pass function name to setTimeout not call it, or you can use anonymous function to call function it its body.
setTimeout(function(){
finishAjax('Info', escape(response))
}
, 450);
Upvotes: 1
Reputation:
If you're using a setTimeout
, your function needs to close over the response variable. Try this:
function(response){
setTimeout(function(){
finishAjax('Info', escape(response));
},
450);
});
Upvotes: 1