我在这里做错了吗?请帮帮我......
example.html的
<script>
$.ajax({
type: "POST",
dataType: "json",
data: {dat: a, pata: id},
url: 'select.php',
success: function(data) {
alert(data.length);
}
});
</script>
select.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "empty_spot";
$connection = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
$q1="select * from seats";
$i = 0;
$all_chairs = array();
$query = mysqli_query($connection,$q1);
while ($obj = mysqli_fetch_assoc($query))
{
$all_chairs[$i] = $obj["status"];
$i++;
}
echo json_encode($all_chairs);
?>
答案 0 :(得分:0)
你的问题就在这里
把它data:{"dat":a,"pata":id}
。如果a和id是变量,则定义它,否则也将它们放在引号