Hello! I am very new to jQuery and javascript programming. I have a program below that checks whether username is taken or not. For now, the PHP script always returns
if(isset($_POST["username"]) )//&& isset($_POST["checking"]))
{
$xml="<register><message>Available</message></register>";
echo $xml;
}
Login function works, but username checking doesn't. Any ideas? Here is all of my code:
$(document).ready(function() {
jQuery.validator.addMethod("checkAvailability",function(value,element){
$.post( "login.php" , {username:"test", checking:"yes"}, function(xml){
if($("message", xml).text() == "Available") return true;
else return false;
});
},"Sorry, this user name is not available");
$("#loginForm").validate({
rules: {
username: {
required: true,
minlength: 4,
checkAvailability: true
},
password:{
required: true,
minlength: 5
}
},
messages: {
username:{
required: "You need to enter a username." ,
minlength: jQuery.format("Your username should be at least {0} characters long.")
}
},
highlight: function(element, errorClass) {
$(element).fadeOut("fast",function() {
$(element).fadeIn("slow");
})
},
success: function(x){
x.text("OK!")
},
submitHandler: function(form){send()}
});
function send(){
$("#message").hide("fast");
$.post( "login.php" , {username:$("#username").val(), password:$("#password").val()}, function(xml){
$("#message").html( $("message", xml).text() );
if($("message", xml).text() == "You are successfully logged in.")
{
$("#message").css({ "color": "green" });
$("#message").fadeIn("slow", function(){location.reload(true);});
}
else
{
$("#message").css({ "color": "red" });
$("#message").fadeIn("slow");
}
});
}
$("#newUser").click(function(){
return false;
});
});