21,886
社区成员
发帖
与我相关
我的任务
分享
include 'conn.php';
$data=array();
$sql="select * from address ";
$result=mysqli_query($conn, $sql);
while($row=mysqli_fetch_array($result)){
$data[]=$row;
}
$arr = array('json'=>$data);
echo json_encode($arr);
<?php
$data = array(
'name' => 'fdipzone'
);
$arr = array('json'=>$data);
header('content-type:application/json');
echo json_encode($arr);
?>
html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<title> js test </title>
</head>
<body>
<script type="text/javascript">
$(function() {
$.ajax({
url: 'server.php',
type: 'POST',
data: {},
dataType: 'json',
success: function (result) {
alert(result['json']['name']);
}
});
});
</script>
</body>
</html>
$.ajax({
url: '...',
type: '...',
data: {...},
dataType: 'json',
success: function (result) {
...
}
});