<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> </head> <body> <form id="Form1" action="1.php" method="post" > 名称:<input name="name" type="text" /><br /> 密码:<input name="password" type="password" /><br /> 手机:<input name="mobile" type="text" /><br /> 说明:<input name="memo" type="text" /><br /> <input type="submit" value="提 交" /> </form> <script type="text/javascript"> //将form转为AJAX提交 function ajaxSubmit(frm, fn) { var dataPara = getFormJson(frm); $.ajax({ url: frm.action, type: frm.method, data: dataPara, success: fn }); } //将form中的值转换为键值对。 function getFormJson(frm) { var o = {}; var a = $(frm).serializeArray(); $.each(a, function () { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ‘‘); } else { o[this.name] = this.value || ‘‘; } }); return o; } $(document).ready(function(){ $(‘#Form1‘).bind(‘submit‘, function(e){ ajaxSubmit(this, function(data){ alert(data); }); e.preventDefault(); }); }); </script> </body> </html>
服务端
<?php var_dump($_POST);
时间: 2024-10-05 05:31:43