AJAX的表單請求POST請求方式
阿新 • • 發佈:2018-12-20
表單資料的提交 action : 資料提交的地址,預設是當前頁面 method : 資料提交的方式,預設是get方式 post: 把資料名稱和資料值用=連線,如果有多個的話,那麼他會把多個數據組合用&進行連線,然後把資料放到url?後面傳到指定頁面 enctype : 提交的資料格式,預設application/x-www-form-urlencoded
<body> <form action="links/1.post.php" method="post"> <input type="text" name="username" placeholder="輸入名字" /> <input type="text" name="age" placeholder="輸入年齡" /> <input type="submit" class="myBtn" value="提交" /> </form> </body>
post與get的區別只在於書寫名字和enctype的區別,post必須新增enctype型別,而get用預設的即可,同時get請求的資料量小且安全性低,資料內容暴露在url後面的連結裡面,而post則可通過傳送引數來傳遞,高效。
<?php header('content-type:text/html;charset="utf-8"'); error_reporting(0); //$_REQUEST $username = $_POST['username']; $age = $_POST['age']; echo "你的名字:{$username},年齡:{$age}"; ?>