html 如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>后台管理系统登录</TITLE><META http-equiv=Content-Type content="text/html; charset=utf-8"><script src="/docs/js/jquery-1.8.1.min.js" ></script></HEAD><body> name: <input type="text" name="name" id="name" value="tom" /><br /> age:<input type="text" name="age" id="age" value="22" /><br /> <textarea name="contents" id="contents"></textarea><br /> <a href="#" οnclick="javascript:tijiao();"> submit </a><div style="height:100px;width:500px;border:1px solid red;" id="shows"></div></BODY></HTML> <script> function tijiao() { $.ajax({ type: "POST", contentType: "application/json", url:'/test1.php',// 跳转到 action data: '{"name":"'+$('#name').val()+'","age":"'+$('#age').val()+'","contents":"'+$('#contents').val()+'"}', dataType: 'json', success: function(result) { $("#shows").html(result.name + "|"+result.age + "|" + result.contents ); } });} </script>
php:
<?php
$string = file_get_contents("php://input");$res = json_decode($string,true);echo json_encode($res);?>