<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> </head> <body> <form action="t1.php" method="post" name="xx"> 用戶名: <input type="text" id="name" name="name" value="zhangsan" /><br /> 密 碼: <input type="text" id="pwd" name="pwd" value="123456" /><br /> 性 別: <input type="text" id="sex" name="sex" value="0" /><br /> <input type="submit" name="" value="提交"> </form> <div></div> <script type="text/javascript"> $('form[name="xx"]').submit(function(){ var form = $(this); // alert(form.attr('method')); $.ajax({ type: form.attr('method'), url: form.attr('action'), data: form.serialize(), dataType: "json", beforeSend: function(){ }, complete:function(){ }, success: function(res){ } }); return false; }); </script> </body> </html>