告別ajax實(shí)現(xiàn)無刷新提交表單

字號(hào):


    通常對(duì)于無刷新提交表單,我們都是運(yùn)用ajax實(shí)現(xiàn)的。前段時(shí)間跟著老大了解到另一種無刷新提交表單的方法?,F(xiàn)在整理出來分享給大家。
    第一種:
    (html頁面)
    代碼如下:
    <!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 style=display:none;>
    </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頁面)
    代碼如下:
    <?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;
    }