if(isset($_POST["search"]) && isset($_SESSION['username'])){
$database = new Database;
$connection = $database -> connect();
$sql = "SELECT surname, name, street, streetNumber FROM customers";
if(!$req = $connection -> prepare($sql)){
echo "e001";
}else{
$req -> execute();
$res = $req -> get_result();
$json = array();
while($row= $res -> fetch_assoc()){
$json['customers:'] = $row;
}
print json_encode($json);
$req -> close();
$database -> disconnect($connection);
}
}
As far as I see this code is pretty much like it's tought here on stack overflow.
So I don't understand why I just won't get a response when I request this via AJAX and look at the network tab in Chrome debug.
Everything works, all the scripts run on, I don't get any errors, just an empty response.
EDIT: Oh, and i tried, i get data from the database with that funcition, tried by echoing without json_encode(), so that can't be the problem.
EDIT: Asked for JS code, doesn't do anything with the response yet since i view the response in the browser.
function loadCustomers() {
$.ajax({
url: 'scripts/backend/customers.php',
type: 'post',
data: {
'search': "Schramm"
},
dataType: "json",
success: function(response, status) {},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
},
});
}
EDIT: The database and tables are set to UTF-8
so it isn't an encoding problem.