ajax簡單頁面

來源:互聯網
上載者:User

標籤:去除   驗證   url   main   style   頁面   rip   else   success   

簡單的註冊頁面運用ajax

首頁面

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script src="../jquery/jquery-1.11.2.min.js"></script>//首先引用jquery檔案
</head>

<body><h1>登入頁面</h1><div>使用者名稱:<input type="text" id="uid" /></div><div>密碼:<input type="text" id="pwd" /></div><input type="button" id="btn" value="登入" /></body><script type="text/javascript">$("#btn").click(function(){    //1.取內容    var uid = $("#uid").val();    var pwd = $("#pwd").val();    //2.拿內容去資料庫驗證    $.ajax({                url:"dlchuli.php",//請求地址        data:{uid:uid,pwd:pwd},//要提交的資料{名稱:值}        type:"POST",//提交的方式        dataType:"TEXT",//傳回型別 dataType中的T必須大寫    TEXT字串 JSON XML        success: function(data){//回呼函數            //使用data之前,對data進行去空格處理                if(data.trim()=="OK")//trim()函數是去除前後的空格                {                    window.location.href = "main.php";                }                else                {                    alert("使用者名稱或密碼錯誤!");                }            }        });    //3.給出提示    })</script>

處理頁面dlchuli.php

<?phpinclude("DBDA.class.php");$db = new DBDA();$uid = $_POST["uid"];$pwd = $_POST["pwd"];$sql = "select pwd from users where uid=‘{$uid}‘";$arr = $db->Query($sql);if($arr[0][0]==$pwd && !empty($pwd))//密碼相等代表正確,密碼為空白代表使用者名稱在資料庫尋找不到{    echo "OK";}else{    echo "NO";}

 

ajax簡單頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.