告別AJAX實(shí)現(xiàn)無刷新提交表單
通常對(duì)于無刷新提交表單,我們都是運(yùn)用ajax實(shí)現(xiàn)的。前段時(shí)間跟著老大了解到另一種無刷新提交表單的方法。現(xiàn)在整理出來分享給大家。
第一種:
(html頁面)
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>無刷新提交表單</title>
<style type="text/css">
ul{ list-style-type:none;}
</style>
</head>
<body>
<iframe name="formsubmit">
</iframe>
<!-- 將form表單提交的窗口指向隱藏的ifrmae,并通過ifrmae提交數(shù)據(jù)。 -->
<form action="form.php" method="POST" name="formphp" target="formsubmit">
<ul>
<li>
<label for="uname">用戶名:</label>
<input type="text" name="uname" id="uname" />
</li>
<li>
<label for="pwd">密 碼:</label>
<input type="password" name="pwd" id="pwd" />
</li>
<li>
<input type="submit" value="登錄" />
</li>
</ul>
</form>
</body>
</html>
(PHP頁面)
復(fù)制代碼 代碼如下:
<?php
//非空驗(yàn)證
if(empty($_POST["uname"]) || empty($_POST["pwd"]))
{
echo "<script type="text/javascript">alert("用戶名或密碼為空!");</script>";
exit;
}
//驗(yàn)證密碼
if($_POST["uname"] != "jack" || $_POST["pwd"] != "123456")
{
echo "<script type="text/javascript">alert("用戶名或密碼不正確!");</script>";
exit;
} else {
echo "<script type="text/javascript">alert("登錄成功!");</script>";
exit;
}
相關(guān)文章:
1. Springboot訪問templates html頁面過程詳解2. Android實(shí)現(xiàn)觸發(fā)html頁面的Button控件點(diǎn)擊事件方式3. PHP去除HTML標(biāo)簽函數(shù)——strip_tags和htmlspecialchars4. PHP中使用DOMDocument來處理HTML、XML文檔的示例5. Python爬蟲工具requests-html使用解析6. HTML DOM setInterval和clearInterval方法案例詳解7. HTML <!DOCTYPE> 標(biāo)簽8. Ajax實(shí)現(xiàn)頁面無刷新留言效果9. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼10. 如何學(xué)習(xí)html的各種標(biāo)簽

網(wǎng)公網(wǎng)安備