I'm having a really weird problem. My jQuery Ajax request is ALSO going to another php ajax script (must go to ajax/sign-in.php and give me an error in ajax/users.php) (without any redirect code) and it's giving me strange errors.
Basically, i have the jQuery Ajax Request:
login = function(){
var data = {
login : $('input[name="login"]').val(),
password : $('input[name="password"]').val()
}
$.ajax({
type: "POST",
url: '../ajax/signin.php',
dataType: 'json',
data: data,
success: function(result){
addLoading('.signIn button');
if (result.success){
//window.location="//aquickgig.com";
console.log('huehue');
}else{
setError(".signIn button", result.error);
}
removeLoading('.signIn');
},
error: function(xhr, ajaxOptions, thrownError){
alert("Error Status: " + xhr.status + " Thrown Errors: "+thrownError);
}
});
}
And my Ajax php script:
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 01 Jan 1996 00:00:00 GMT');
header('Content-Type: application/json');
include_once($_SERVER['DOCUMENT_ROOT'] . '/lib/users.php');
$users = new Users();
isset($_POST['login']) ? $login = $_POST['login'] : $login = null;
isset($_POST['password']) ? $password = $_POST['password'] : $password = null;
$resp = array();
if (strlen($login) == 0 || strlen($password) == 0){
$resp['error'] = "Please, fill all the fields";
}
elseif (strlen($login) > 50 || strlen($password) > 50){
$resp['error'] = "Invalid number of characters. Usernames and password cannot be above 50 characters";
}
else{
$resp['success'] = "something";
}
echo json_encode($resp);
?>
When i do the request, the console doesn't give me scripts errors and it does the request. But on the catch, give me the answer: Error Status 200 Thrown Errors: SintaxeError: Unexpected token <.
Also, the response from request is Fatal error: Class 'Users' not found in C:\xampp\htdocs\ajax\users.php on line 8. I NEVER called the users.php script.
Trying to figure out the problem, i noticed that when i remove or comment the line include_once($_SERVER['DOCUMENT_ROOT'] . '/lib/users.php'); from sign-in.php, it works perfectly.
I really confused, don't know what's happening. Thank you!