PHP+JQUERY operates JSON instances

墨辰丷
Release: 2023-03-27 19:52:02
Original
1302 people have browsed it

This article mainly introduces the method of PHP JQUERY to operate JSON, and analyzes the related techniques of PHP jQuery combined with ajax to realize json format data operation based on specific examples. Friends in need can refer to the following

The examples of this article are described Learn how to use PHP JQUERY to operate JSON. Share it with everyone for your reference, the details are as follows:

json.html Code:

<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({
&#39;type&#39;:"POST",
&#39;url&#39;:&#39;json_encode.php&#39;,
&#39;dataType&#39;:&#39;json&#39;,
&#39;data&#39;: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="提交">
<p style="font-size:14px;" id="view">
</p>
</body>
</html>
Copy after login

json_encode.php Code

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

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

jQuery sends a request to the PHP server through Ajax and returns JSONdata

JSON and Math use case analysis in JS

Compare the three implementations of Ajax andJSONParsing

The above is the detailed content of PHP+JQUERY operates JSON instances. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template