表单和AJAX提交请求
前后端交互过程
一、简介
前后端的交互过程就是HTTP协议的处理过程:请求与响应的处理过程。单纯只有前端,无法使用后台服务器的能力,或者无法访问数据库,如果单纯只有后端,也无法形成业务流程,无法为客户产生价值。
三种方式:
(1)资源获取型:GET请求+URL地址
(2)数据提交型:POST请求+URL地址+请求正文
(3)AJAX提交:利用异步提交方式,在不刷新当前页面情况下,提交数据给后台
第三种就类似于,如下两种情况
二、POST请求
以下请求方式使用form表单的形式发送post请求
(1)必须使用form标签将所有表单元素包裹起来
(2)必须要在form标签中指定action属性
(3)必须要在form标签中指定method属性
<form action="../PHP/login.php" method="post">
(4)必须要确保在form标签内,有至少一个按钮,且按钮 type="submit"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ymqyyds</title>
<style>
div {
width: 310px;
height: 75px;
margin: auto;
}
.title {
color: rgb(6, 255, 52);
font-size: 30px;
text-align: center;
margin-top: 200px;
padding-bottom: 10px; /*和底部下一个容器相隔一点距离*/
font-weight: bold; /*加粗*/
font-style: italic; /*斜体*/
}
input {
width: 300px;
height: 50px;
background-color: antiquewhite;
border-radius: 5px; /*让边框看起来圆润一点*/
text-align: center;
margin: auto;
}
button {
width: 310px;
height: 50px;
background-color: fuchsia;
color: chartreuse;
font-size: 20px;
font-weight: bold; /*加粗*/
font-style: italic; /*斜体*/
border-radius