我在错误语句中获得了数据库的完整结果。所以有数据通过低谷,但我不知道为什么它会出错我做错了。现在工作几个小时,找不到解决方案。希望有人可以帮助我
这是我的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);
?>
这是我的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>
答案 0 :(得分:1)
我认为问题是你在ajax函数中设置了DataSet queue = DBMgr.GetDataSet("SELECT * FROM queue");
DataTable missedQueue = queue.Tables[0].Copy();
但响应是这样的html:
dataType: 'json'
您应该将所有html保存在字符串
中echo "<tr id=".$row["id"]."><td>".$row["roepnaam"]."</td>"
并发送json响应
$data = "";
$data .= "<tr id=".$row["id"]."><td>".$row["roepnaam"]."</td>";
$data .= "<td>".$row["achternaam"]."</td>";
....
或删除echo json_encode(['data'=>$data]);
并发送html
dataType: 'json'