I get the complete result of the database inside the error statement. So there is data passing trough but I have no clue why its going to an error i'm doing wrong. Working for hours now and find no solution. Hope somebody can help me
This is my select_clienten.php
<?php
//database configuration
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '********';
$dbName = '********';
//connect with the database
$conn = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
$sql = "SELECT * FROM clienten";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr id=".$row["id"]."><td>".$row["roepnaam"]."</td>";
echo "<td>".$row["achternaam"]."</td>";
echo "<td>".$row["email"]."</td>";
echo "<td><span class='glyphicon glyphicon-edit bewerk'></span></td>";
echo "<td><span class='glyphicon glyphicon-trash verwijder'></span></td></tr>";
}
} else {
echo "0 results";
}
echo json_encode($data);
?>
This is my index.php.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>title</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery- ui.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" href="/css/custom.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
var data;
$.ajax(
{type: 'get',
url: './select_clienten.php',
data: "",
dataType: 'json',
success:function(data)//we got the response of ajax :)
{
$("#test").html(data);
},
error:function(data)
{
//no respons show error.
alert ("error!");
alert(JSON.stringify(data)) //we give an alert of the error when there is no respons from ajax
;}
}); //end of ajax function.
});
</script>
<div id="test">
<!-- show data json here -->
</div>
</body>
</html>