zoukankan      html  css  js  c++  java
  • php第二十一节课

    AJAX

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="jquery-1.11.2.min.js"></script>
    </head>

    <body>
    <div><input type="text" id="uid" /><span id="xinxi"></span></div>
    </body>

    <script type="text/javascript">
    $(document).ready(function(e) {

    $("#uid").blur(function(){

    //把文本框的值取出来
    var uid = $(this).val();

    //调用ajax
    $.ajax({

    url:"ChuLi.php",//处理页面
    data:{u:uid}, //传递的数据,JSON数据
    type:"POST", //提交方式
    datatype:"TEXT", //返回数据的类型
    success:function(data){ //回调函数

    if(data=="OK")
    {
    var str = "该用户名可以使用!";
    $("#xinxi").html(str);
    }
    else
    {
    var str = "<span style='color:red'>该用户名已经存在!</span>";
    $("#xinxi").html(str);
    }
    }

    });


    })

    });
    </script>

    </html>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="jquery-1.11.2.min.js"></script>
    </head>

    <body>


    </body>
    <script type="text/javascript">
    $(document).ready(function(e) {
    $.ajax({
    url:"error.php",
    datatype:"TEXT",
    success: function(data){

    alert(data);
    }
    });
    });
    </script>
    </html>

    <?php
    $uid = $_POST["u"];
    $pwd = $_POST["p"];

    include("DBDA.php");
    $db = new DBDA();

    $sql = "select count(*) from Users where Uid='{$uid}' and Pwd='{$pwd}'";

    $attr = $db->Query($sql);

    if($attr[0][0]==1)
    {
    echo "OK";
    }
    else
    {
    echo "NO";
    }

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="jquery-1.11.2.min.js"></script>
    </head>

    <body>
    <h1>登录</h1>
    <div>用户名:<input type="text" id="uid" /></div>
    <div>密码:<input type="text" id="pwd" /></div>
    <div><input type="button" id="btn" value="登录" /></div>

    <div id="test" style="100px; height:100px; background-color:#F30"></div>

    </body>
    <script type="text/javascript">
    $(document).ready(function(e) {
    /*
    数据传输:同步:传输必须等到接收方接收到,才能传下一个。异步:传输不用等到对方接收就可以继续传递。

    AJAX:同步:AJAX必须处理完才能继续向下执行。异步:AJAX在处理数据的同时代码继续往下执行
    */



    $("#btn").click(function(){

    var uid = $("#uid").val();
    var pwd = $("#pwd").val();

    $.ajax({

    url:"LoginChuLi.php",
    data:{u:uid,p:pwd},
    type:"POST",
    dataType:"TEXT",
    success: function(data){

    if(data=="OK")
    {
    window.location = "test.php";
    }
    else
    {
    alert("用户名或密码错误!");
    }

    },

    });

    })

    $("#test").click(function(){
    $("#test").html("");
    $.ajax({
    async:false, //变为同步AJAX
    url:"TestCL.php",
    datatype:"TEXT",
    success:function(data){
    $("#test").html(data);

    }
    });


    alert($("#shuju").html());

    })

    });
    </script>
    </html>

    <?php
    //接收传递过来的参数
    $uid = $_POST["u"];
    //查数据库
    include("DBDA.php");
    $db = new DBDA();

    $sql = "select count(*) from Users where Uid='{$uid}'";

    $attr = $db->Query($sql);

    if($attr[0][0] == 1)
    {
    echo "NO";
    }
    else
    {
    echo "OK";
    }

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <?php

    include("DBDA.php");
    $db = new DBDA();

    $sql = "select * from User";

    $attr = $db->Query($sql);

    echo $attr[0][1];

    ?>
    </body>
    </html>

  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/xiongxiaobai/p/5502022.html
Copyright © 2011-2022 走看看