告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單
通常對(duì)于無(wú)刷新提交表單,我們都是運(yùn)用ajax實(shí)現(xiàn)的。前段時(shí)間跟著老大了解到另一種無(wú)刷新提交表單的方法。現(xiàn)在整理出來(lái)分享給大家。
第一種:
(html頁(yè)面)
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>無(wú)刷新提交表單</title>
<style type="text/css">
ul{ list-style-type:none;}
</style>
</head>
<body>
<iframe name="formsubmit">
</iframe>
<!-- 將form表單提交的窗口指向隱藏的ifrmae,并通過(guò)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頁(yè)面)
復(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. 使用XSL將XML文檔中的CDATA注釋輸出為HTML文本2. html小技巧之td,div標(biāo)簽里內(nèi)容不換行3. php 下 html5 XHR2 + FormData + File API 上傳文件操作實(shí)例分析4. html清除浮動(dòng)的6種方法示例5. HTML中l(wèi)ink標(biāo)簽屬性詳解6. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案7. 不要在HTML中濫用div8. 如何利用js在兩個(gè)html窗口間通信9. 前端html+css實(shí)現(xiàn)動(dòng)態(tài)生日快樂(lè)代碼10. python爬蟲beautifulsoup解析html方法
