This article illustrates the simple implementation of the JSON data by PHP based on jquery Ajax technology. Share to everyone for your reference, specific as follows:
HTML page:
PHP Page:
<?php
Header ("Content-type:text/html;charset=utf-8");
$username = $_post[' username '];
$age = $_post[' age '];
$job = $_post[' job '];
$json _arr = Array ("username" => $username, "age" => $age, "job" => $job);
$json _obj = Json_encode ($json _arr);
echo $json _obj;
? >
Use POST method
<script type= "Text/javascript" >
$ (function () {
$ ("#send"). Click (function () {
var cont = { username:$ ("input") [0].value,age:$ ("Input") [1].value,job:$ ("Input") [2].value};
var url = ' ab.php ';
$.post (url,cont,function (data) {
var res = eval ("(+ Data +)");/Convert to Object
var str = res.username + res.age + Res.job;
$ ("#result"). html (str);
});
}
); </script>
For more information about PHP interested readers can view the site topics: "Php+ajax Tips and Applications Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary ( including word,excel,access,ppt), the "Summary of PHP date and time usage", "PHP Introduction to Object-oriented Programming", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.