45fan.com - 路饭网

搜索: 您的位置主页 > 电脑频道 > 编程代码 > 阅读资讯:php+jquery操作jsob实例有哪些?

php+jquery操作jsob实例有哪些?

2017-08-24 07:49:08 来源:www.45fan.com 【

php+jquery操作jsob实例有哪些?

本文实例讲述了PHP+JQUERY操作JSON的方法。分享给大家供大家参考,具体如下:

json.html 代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>PHP Json传输数据</title>
</head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function(){
$("#submit").click(function(){
var text = $("input").serialize();
$.ajax({
'type':"POST",
'url':'json_encode.php',
'dataType':'json',
'data':text,
success:insertData
});
});
});
function insertData(data){
var str = "姓名="+data.name+"<br/>性别="+data.sex+"<br/>年龄="+data.age;
$("#view").html(str);
}
</script>
<body>
姓名:<input name="name" id="name" type="text" value=""><br/>
性别:<input name="sex" id="sex" type="text" value=""><br/>
年龄:<input name="age" id="age" type="text" value="">
<input type="submit" name="submit" id="submit" value="提交">
<div style="font-size:14px;" id="view">
</div>
</body>
</html>

json_encode.php 代码

<?php
header("Content-type:text/html;charset=utf8");
include("Json.php");
$name = $_POST['name'];
$sex = $_POST['sex'];
$age = $_POST['age'];
$json_arg = array('name'=>$name,'sex'=>$sex,'age'=>$age);
$json = new JSON;
$json_result = $json->encode($json_arg);
echo $json_result;
?>

PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat

在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

希望本文所述对大家PHP程序设计有所帮助。


本文地址:http://www.45fan.com/bcdm/91502.html
Tags: 操作 JSON PHP+jQuery
编辑:路饭网
推广内容
推荐阅读
热门推荐
推荐文章
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部