Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

JQUERY PHP (XHR LOADING FAILED) #304

Open
hubhubace opened this issue Aug 26, 2017 · 0 comments
Open

JQUERY PHP (XHR LOADING FAILED) #304

hubhubace opened this issue Aug 26, 2017 · 0 comments

Comments

@hubhubace
Copy link

hubhubace commented Aug 26, 2017

I am trying to validate username field but post to php not working.returns error xhr failed loading

$('#username').blur(function(){
var u = $("#username").val();
if(u != ""){
$("#unamestatus").html('checking ...');
$.ajax({
url:"php/name_check.php",
method:"POST",
data:{usernamecheck:u},
success:function(data){
$('#unamestatus').fadeIn().html(data);
setTimeout(function(){
$('#unamestatus').fadeOut("Slow");
}, 2000);
}
`` });

}

});

});
//here is php code
public function name_check(){
global $conn;
// Ajax calls this NAME CHECK code to execute
if(isset($_POST["usernamecheck"])){
echo $_POST;

$username = preg_replace('#[^a-z0-9]#i', '', $_POST['usernamecheck']);

$sql = "SELECT id FROM users WHERE username='$username'";
$query = mysqli_query($conn, $sql); 
$uname_check = mysqli_num_rows($query);
if (strlen($username) < 3 || strlen($username) > 16) {
    echo '<strong style="color:#F00;">3 - 16 characters please</strong>';
    exit();
}
if (is_numeric($username[0])) {
    echo '<strong style="color:#F00;">Usernames must begin with a letter</strong>';
    exit();
}
if ($uname_check < 1) {
    echo '<strong style="color:#009900;">' . $username . ' is OK</strong>';
    exit();
} else {
    echo '<strong style="color:#F00;">' . $username . ' is taken</strong>';
    exit();
}

}
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant