getStudents.js
$("#submit").click(function(){
$.ajax({
url: "displayStudents.php?branchCode=1",
datatype:"JSON",
success: function(obj){
for(var i=0; i<obj.length; i++){
$("ul").append(obj[i].name)
}
}
})
});
displayStudents.php
<?php
include 'config.php';
$branchCode = $_GET['branchCode'];
$list = mysqli_query($con, "Select * from student where branchCode = '$branchCode' ORDER BY rollNo");
$result = array();
while($row = mysqli_fetch_array($list)){
$result[] = array("RollNo"=>$row['rollNo'], "Name"=>$row['name']);
}
header("Content-type: application/json");
echo json_encode($result);
?>
php文件'displayStudents.php'正确发送json,但我无法显示学生的姓名。