[eluser]Daksh Mehta[/eluser]
yes, i am using Ajax to validate username if its available or not. that's it .
And i am beginner, so i can judge it.
Here is my js file:
Code:
user_validated = 0;
passwd_validated = 0;
function user_available(){
$.ajax({
type: "POST",
url: "http://localhost:8888/ptcan/index.php/ajax/username_available/"+$("#username").val(),
success: function(msg){
if(msg == 1){
$("#username_status").html("<font class=\"succ\">"+$("#username").val()+" is available!</font>");
user_validated = 1;
reg_validate();
}
else {
$("#username_status").html("<font class=\"err\">"+$("#username").val()+" is not available, try again!</font>");
user_validated = 0;
reg_validate();
}
}
})
}
function pass_check(){
if(($("#password").val() != $("#password2").val())){
$("#password_error").html("<span class=\"err\">Password do not matches!</span>");
passwd_validated = 0;
}
else {
$("#password_error").html("<span class=\"succ\">Password matched!</span>");
passwd_validated = 1;
}
reg_validate();
}
function reg_validate(){
if((user_validated == 1) && (passwd_validated == 1))
$("#regBtn").css("display", "block");
else
$("#regBtn").css("display", "none");
}
Here is my ajax controller:
Code:
<?php
class Ajax extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function username_available($username = ""){
if($username != ""){
$q = $this->db->query("SELECT username FROM members WHERE username = ?", array($username));
if($q->num_rows() == 0){
echo "1";
}
else {
echo "0";
}
}
else {
echo "<span class=\"err\">Username is required!</span>";
}
}
}
?>