标签:
1.php文件如下 header(‘Content-Type:text/html;charset=utf-8‘); ?> <script type="text/javascript"src="http://code.jquery.com/jquery.min.js"></script> <scripttype="text/javascript"> $(function() { $("#subbtn").click(function() { var params = $(‘input‘).serialize(); var url = "你的服务器端 php"; $.ajax({ type: "post", url: url, dataType: "json", data: params, success: function(msg){ var tishi = "您提交的姓名为:" + msg.name + "<br/> 您提交的密码为:" + msg.password; $("#tishi").html(tishi); $("#tishi").css({color: "green"}); } }); }); }); </script> <p><labelfor="name">姓名:</label> <inputid="name"name="name"type="text"/> </p> <p><labelfor="password">密码:</label> <inputid="password"name="password"type="password"/> </p> <spanid="tishi"></span> <p><inputid="subbtn"type="button"value="ajax 测试"/></p> 2.服务器 PHP 代码如下 <?php echo json_encode($_POST); |
标签:
原文地址:http://www.cnblogs.com/qhorse/p/4607309.html