json.html 代码
<script type="text/javascript" src="js/<a%20style=" color: text-decoration:underline title="jquery" href="https://www.php.cn/zt/15736.html" target="_blank">jquery.js"></script>
<script type="text/javascript"><br> $(function(){<br> $("#submit").click(function(){<br> var text = $("input").serialize();<br> $.ajax({<br> 'type':"POST",<br> 'url':'json_encode.<a style="color:#f60; text-decoration:underline;" title= "php" href="https://www.php.cn/zt/15714.html" target="_blank">php', <br> 'dataType':'json',<br> 'data':text,<br> success:insertData<br> });<br> });<br> }); <p> function insertData(data){<br> var str = "姓名="+data.name+"<br/>性别="+data.sex+"<br/>年龄="+data.age;<br> $("#view").html(str);<br> }<br> </script>
姓名:
性别:
年龄:
json_encode.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;
?>











