使用ajax / jquery显示数据库中的详细信息

时间:2017-02-16 19:50:35

标签: php jquery ajax

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,但我无法显示学生的姓名。

0 个答案:

没有答案