I have been trying to enable Submit Button after the AJAX Request success. The validation is in PHP file which has following code
if(!empty($_POST["username"])) {
$fetch = "SELECT * FROM student WHERE std_username='" . $_POST["username"] . "'";
$result = mysqli_query($con, $fetch);
$user_count = mysqli_num_rows($result);
if($user_count>0) {
echo "<span class='status-not-available'> Username Not Available.</span>";
}else{
echo "<span class='status-available'> Username Available.</span>";
}
}
and this is AJAX
function checkAvailability() {
$("#loaderIcon").show();
jQuery.ajax({
url: "check_availability.php",
data:'username='+$("#username").val(),
type: "POST",
success:function(data){
$("#user-availability-status").html(data);
$("#loaderIcon").hide();
},
error:function (){}
});
}
I have used this is success what it does is disable the submit button even the data matches the request or not, the button stays disabled
$("#submit").attr("disabled", true);
and following in error
$("#submit").attr("disabled", false);
I have gone throught these questions and tried the solutions but those solutions didn't work out for me.
jQuery: Re-enabling disabled input buttons after 'success:' is run and
Disable Button while AJAX Request
this is the HTML
<form method="POST">
<label>Check Username:</label>
<input name="username" type="text" id="username" class="demoInputBox" onBlur="checkAvailability()"><span id="user-availability-status"></span><br>
<label>Check Username:</label>
<input name="email" type="text" id="email" class="demoInputBox" onBlur="checkAvailabilitye()"><span id="email-availability-status"></span> <br>
<input type="submit" id="submit">
</form>
Thanks in advance!