直接使用form表单提交
-
使用表单action属性
提交的地址直接写在form表单的action属性中
''' html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Insert title here</title> </head> <body> <form action="http://localhost:8080/user" method="post"> username:<input type="text" name="username" /><br>password:<input type="password" name="password" /> <br>
<input type="submit" value="登录"> </form> </body> </html> '''
使用ajax提交
- form表单中使用
<input type="button" onclick="mySubmit">提交,在mySubmit中使用ajax获取元素数据,使用ajax提交到远程服务器。 - form表单中使用
<input type="submit">促发表单的提交,input的type必须为submit - form表单中使用
<form onsubmit="mySubmit">促发表单提交,input的type必须为submit。mySubmit函数返回true时提交到远程服务器,false不提交到远程服务器。