网站建设资讯

NEWS

网站建设资讯

ajax返回json数据-创新互联


Ajax利用JSON进行前后台交互


获取所有用户信息







%3Cbr%20/%3E%20function%20getJson%28RequestData%2CURL%29%7B%3Cbr%20/%3E%20var%20reJson%3B%3Cbr%20/%3E%20%24.ajax%28%7B%3Cbr%20/%3E%20type%3A%27POST%27%2C%3Cbr%20/%3E%20url%3AURL%2C%3Cbr%20/%3E%20data%3ARequestData%2C%3Cbr%20/%3E%20async%3Afalse%2C%20//%u4E3A%u4E86%u7B80%u4FBF%uFF0C%u8BBE%u7F6E%u4E3A%u540C%u6B65%u64CD%u4F5C%3Cbr%20/%3E%20cache%3A%20false%2C%3Cbr%20/%3E%20success%3Afunction%28responseData%29%7B%3Cbr%20/%3E%20reJson%3DresponseData%3B%3Cbr%20/%3E%20%7D%3Cbr%20/%3E%20%7D%29%3B%3Cbr%20/%3E%20return%20reJson%3B%3Cbr%20/%3E%20%7D%3Cbr%20/%3E%20function%20getAllUsers%28%29%7B%3Cbr%20/%3E%20var%20url%20%3D%20%22json.php%22%3B%3Cbr%20/%3E%20var%20request%20%3D%20%27action%3Dget_all_users%27%3B%3Cbr%20/%3E%20//%u4ECE%u540E%u53F0%u83B7%u53D6%u5E76%u89E3%u6790%uFF0C%u7531%u4E8E%u4E0A%u9762%u5C01%u88C5ajax%u91C7%u7528%u7684%u662F%u540C%u6B65%u8FD4%u56DE%uFF0C%3Cbr%20/%3E%20//%u6240%u4EE5%u8FD9%u6837%u64CD%u4F5C%u80FD%u6210%u529F%u83B7%u53D6%u8FD4%u56DE%u6570%u636E%3Cbr%20/%3E%20var%20json%20%3D%20getJson%28request%2Curl%29%3B%3Cbr%20/%3E%20var%20users%20%3D%A0%20eval%28%27%28%27+%20json%20+%27%29%27%29%3B//%u5C06%u5B57%u7B26%u4E32%u8F6C%u5316%u4E3Ajson%u5BF9%u8C61%20%3Cbr%20/%3E%20var%20usersHtml%20%3D%20%27%3Cbr%20/%3E%20%3Cspan%3EAjax%u8FD4%u56DE%u7684JSON%u5B57%u7B26%u4E32%uFF1A%3C/span%3E%3Cbr%20/%3E%20%27%3Cbr%20/%3E%20+%20json%20+%20%27%3Cbr%20/%3E%20%3Cbr%20/%3E%20%3Cspan%3E%u89E3%u6790%u51FA%u6765%u7684%u7ED3%u679C%u4E3A%uFF1A%3C/span%3E%3Cbr%20/%3E%20%27%3B%3Cbr%20/%3E%20for%28var%20i%3D0%3Bi%3Cusers.length%3B++i%29%7B%3Cbr%20/%3E%20usersHtml%20+%3D%20%27userId%20%3D%20%27%20+%20users%5Bi%5D.userId%20+%20%27%3Cbr%20/%3E%20%27%3Cbr%20/%3E%20+%20%27userName%20%3D%20%27%20+%20users%5Bi%5D.userName%20+%20%27%3Cbr%20/%3E%20%27%3B%3Cbr%20/%3E%20%7D%3Cbr%20/%3E%20//%u628A%u6784%u9020%u7684HTML%u5229%u7528jQuery%u52A8%u6001%u663E%u793A%u5230%u9875%u9762%3Cbr%20/%3E%20%24%28%27%23users%27%29.empty%28%29.html%28usersHtml%29%3B%3Cbr%20/%3E%20%7D%3Cbr%20/%3E%20


成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、成都网站制作、大悟网络推广、重庆小程序开发、大悟网络营销、大悟企业策划、大悟品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;成都创新互联公司为所有大学生创业者提供大悟建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com


//接受请求参数并根据参数选择操作
if(isset($_POST['action'])&&$_POST['action']!=""){
switch($_POST['action']){
case 'get_all_users': getAllUsers(); break;
default:
}
}

//处理请求:以JSON格式返回所有用户信息
function getAllUsers(){
$users = array(
array("userId"=>1,"userName"=>"Raysmond"),
array("userId"=>2,"userName"=>"雷建坤"),
array("userId"=>3,"userName"=>"Rita")
);
echo json_encode($users);
}
?>

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


分享题目:ajax返回json数据-创新互联
网页地址:http://cdweb.net/article/degdcj.html