
PK 
<!-- Modal -->
<div class="modal fade" id="userlogin" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog userlogin modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-center">User Login</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="UserLoginForm" method="POST">
<p id="loginError" style="color:red; text-align:center;"></p>
<div class="control-group form-group">
<div class="controls">
<label>Username:</label>
<input type="text" class="form-control" id="username" name="username" required data-validation-required-message="Please enter Mobile Number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Password:</label>
<input type="password" class="form-control" id="password" name="password" required data-validation-required-message="Please enter your password.">
<p class="help-block text-danger"></p>
<p style="color:red; text-align: center;"><?=(!empty($error_msg))?$error_msg:'';?></p>
</div>
</div>
<div class="modal-footer text-center">
<button type="submit" class="btn btn-primary" name="sendLogin" id="sendLogin">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script>
$('#UserLoginForm').on('submit', function(e) {
e.preventDefault();
var username = $('#username').val();
var password = $('#password').val();
$("#loginError").html("");
$("#sendLogin").prop("disabled", true).text("Logging in...");
$.ajax({
url: "login-ajax.php",
type: "POST",
data: {username: username, password: password},
dataType: 'json',
xhrFields: { withCredentials: true },
success: function(data){
$("#sendLogin").prop("disabled", false).text("Login");
if(data.status === "success"){
window.location.href = "useradmin/dashboard.php";
} else {
$("#loginError").html(data.message || "Login failed.");
}
},
error: function(xhr, status, error) {
$("#sendLogin").prop("disabled", false).text("Login");
console.log("Full error details:");
console.log("Status:", status);
console.log("Error:", error);
console.log("Response text:", xhr.responseText);
console.log("Status code:", xhr.status);
// Check if response contains PHP error
if (xhr.responseText.includes('<b>') || xhr.responseText.includes('PHP Error') || xhr.responseText.includes('Notice:') || xhr.responseText.includes('Warning:')) {
$("#loginError").html("Server error occurred. Please check PHP configuration.");
} else if (xhr.responseText.trim() === '') {
$("#loginError").html("Empty response from server. Please try again.");
} else {
// Try to parse as text to see what we got
try {
// If it's HTML but not JSON, show generic error
if (xhr.responseText.startsWith('<')) {
$("#loginError").html("Server returned HTML instead of JSON. Check for PHP errors.");
} else {
$("#loginError").html("Connection error: " + error);
}
} catch (e) {
$("#loginError").html("Login failed. Please try again.");
}
}
}
});
});
</script>


PK 99