HTML Code復(fù)制內(nèi)容到剪貼板
- <!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頁面:form.php)
-
- <?php
-
- if(empty($_POST['uname']) || empty($_POST['pwd']))
- {
- echo '<script type="text/javascript">alert("用戶名或密碼為空!");</script>';
- exit;
- }
-
- if($_POST['uname'] != 'jack' || $_POST['pwd'] != '123456')
- {
- echo '<script type="text/javascript">alert("用戶名或密碼不正確!");</script>';
- exit;
- } else {
- echo '<script type="text/javascript">alert("登錄成功!");</script>';
- exit;
- }
HTML Code復(fù)制內(nèi)容到剪貼板
- <!DOCTYPE HTML>
- <html lang="en-US">
- <head>
- <meta charset="utf-8">
- <title>iframe提交表單</title>
- </head>
- <body>
- <iframe name="myiframe" style="display:none;" onload="iframeLoad(this);"></iframe>
- <form action="form.php" target="myiframe" method="POST">
- 用戶名:<input type="text" name="username" /><br/>
- 密 碼:<input type="password" name="userpwd" /><br/>
- <input type="submit" value="登錄" />
- </form>
- <script type="text/javascript">
- function iframeLoad(iframe){
- var doc = iframe.contentWindow.document;
- var html = doc.body.innerHTML;
- if(html != ''){
-
- var obj = eval("("+html+")");
-
- if(obj.status < 1){
- alert(obj.msg);
- }else{
- alert(obj.msg);
- window.location.href="http://www.baidu.com";
- }
- }
- }
- </script>
- </body>
- </html>
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <?php
- //設(shè)置時區(qū)
- date_default_timezone_set('PRC');
- /*
- 返回的提交消息
- status:狀態(tài)
- msg:提示信息
- */
- $msg = array('status'=>0,'msg'=>'');
- //獲取提交過來的數(shù)據(jù)
- $name = $_POST['username'];
- $pwd = $_POST['userpwd'];
- //模擬登錄驗證
- $user = array();
- $user['name'] = 'jack';
- $user['pwd'] = 'jack2014';
- if($name != $user['name']){
- $msg['msg'] = '該用戶未注冊!';
- $str = json_encode($msg);
- echo $str;
- exit;
- }else if($pwd != $user['pwd']){
- $msg['msg'] = '輸入的密碼錯誤!';
- $str = json_encode($msg);
- echo $str;
- exit;
- }
- $msg['msg'] = '登錄成功!';
- $msg['status'] = 1;
- $str = json_encode($msg);
- echo $str;
以上內(nèi)容是小編給大家介紹的基于HTML實現(xiàn)表單提交后無刷新頁面的相關(guān)內(nèi)容,希望對大家有所幫助!