form form to submit data to the server

1. What is a form?

Single table used for data collection in the web page

<form action="/login" action='' method='POST' target='_blank'>
    <input type="text" name="user_name" />
    <input type="password" name="password" />
    <button type="submit">提交</button>
</form>

2. Common attributes of form

action: 
	需要提交数据到目的地的url地址
target:	
	属性用来规定 在何处打开 action URL
	常见的有两种: _blank在新窗口打开跟_self在原窗口页面打开
method:	
	 提交的方式 : GET跟POST方式两种  
	 get:只能提交少量,简单的数据,并且form表单中默认的提交方式就是GET
	 post:提交大量,复杂的数据
enctype:  
     向服务器提交的数据是否进行编码
	 application/x-www-form-urlencoded (默认)
	 multiparty/form-data (文件上传必须使用该值)
	 text/plain (很少用)

3. Disadvantages of form submission:

  1. A page jump will occur (default behavior)
  2. After submitting the data, the data will be cleared, and the rendering of the original page will be cleared, and the user experience is too bad.
    Solution:
  3. Use form to collect data, use ajax to submit data (listen to the submit event of the form, and block the default behavior of the page jump in the function content)

Guess you like

Origin blog.csdn.net/Serena_tz/article/details/113932348