求源代码啊
老师有没有源代码
老师有没有源代码
2016-01-12
前端json的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>json2实战</title>
<script type="text/javascript" src="../json/jquery-1.7.min.js"></script>
</head>
<body>
<script type="text/javascript">
$("document").ready(function(){
var url="shizhan.php";
var data={"do":"first"};
$.getJSON(url,data,function(res){
$("#username").val(res.username);
$("#password").val(res.password);
});
var data={"do":"second"};
$.getJSON(url,data,function(res){
// $("#members").val(res[2].address);
$("#members").val(res.third.members.username);
});
var data={"do":"third"};
$.getJSON(url,data,function(res){
$("#address").val(res.address[2].username);
});
});
</script>
<h2>一维数组巩固练习</h2>
<input type="text" name="username" id="username"><br>
<input type="password" name="password" id="password"><br>
<h2>多维数组巩固练习</h2>
<textarea id="members"></textarea>
<textarea id="address"></textarea>
</body>
</html>
服务器端的shizhan.php代码:
<?php
// 1'
$member['username']="mukewang";
$member['password']="mukewang";
$do = $_REQUEST['do'];
// 2
$members['1']['username']="慕课网";
$members['1']['password']="mukewang";
$members['2']['username']="gfds";
$members['2']['password']="haha";
$members['2']['address']="朝阳";
$members['third']['members']['username']="第三个用户值";
// 3
class addressClass{
public $address=array();
public function setAddress($array){
$this->address=$array;
}
public function getAddress(){
return $this->address;
}
}
$addressObj=new addressClass();
$addressObj->setAddress($members);
switch($do){
case "first":
echo json_encode($member);
break;
case "second":
echo json_encode($members); //后面的$members其实对应的是上面的二维数组
break;
case "third":
echo json_encode($addressObj);
break;
}
举报