Integrate A Php Function With Jquery - Check If User Already Exists In Db
Solution 1:
If you are using jQuery validation plugin then here is the solution. This is active code. you need to use remote: . This is my existing code. This will help you to get idea.
$("form#form-join-1").validate({rules: {
sponsorID: {
required:true,
minlength:5,
remote:"ajax.php"
},
slcchild: {
required :true,
remote : {
url:"ajax.php",
type:"post",
data: {
action :'child-validation',
parent_node :function(){
return$('input#sponsorID').val();
}
}
}
}
},messages: {
sponsorID: {
required:"Enter a Sponsor ID",
minlength:$.format("Enteratleast {0} characters"),
remote:$.format("{0} isalreadyinuse")
},
slcchild: {
required:"Select A node",
remote:$.format("{0} isnotempty")
}
}
});
Here is complete guideline. Following this link. They have example code. http://imamiscool.wordpress.com/2009/06/29/check-email-availability-using-jquery%E2%80%99s-ajax-part-2-easy-way/
Solution 2:
Try this, You need to add remote: "usernamecheck.php"
Assumed your php file name is usernamecheck.php
username: {
minlength:5,
maxlength:20,
required:true,
wordonly:true,
remote:"usernamecheck.php"
},
Solution 3:
One of the easier ways is to use one of jQuery's Ajax functions, .load()
So first you make an HTML div where you want your dynamically generated content to be:
<div id="area_to_load_at">
This text will be replaced when JS runs changeArea()
</div>
Next you make a Javascript function that's just for changing the div:
functionchangeArea()
{
var loadTo = "#area_to_load_at";
var loadFrom = "your_file_that_checks_if_the_username_is_taken.php";
$(loadTo).load(loadFrom);
}
Then anywhere in the Javascript where you want it, like right after your validation, just call:
changeArea();
Post a Comment for "Integrate A Php Function With Jquery - Check If User Already Exists In Db"