程序代码:php
<html> <head> <title>AJAX的简单使用</title> </head> <script src="../jquery-1.10.2.min.js"></script> <script> $(document).ready(function (){ $("#tijiao").click(function(){ $.ajax({ type:"post", //数据发送方式 url:"./returnData.php", //后台处理程序 dataType:"json", //接收数据格式 data:$("input").serialize(), //序列化提交的值 success:function(msg){ // alert(msg.name+msg.password); var backdata = "你输入的姓名是:"+msg.name+"<br>你输入的密码是:"+msg.password; $("#backdata").html(backdata); $("#backdata").css({color:"red"}); } }); }); }); </script> <body> 姓名:<input type="text" id="name" name="name"></br> 密码:<input type="password" id="password" name="password"></br> <span id="backdata"></span></br> <input type="button" id="tijiao" value="提交数据"> </body> </html>
returnData.php:css
<?php echo json_encode($_POST); ?>
演示效果:html