Blogger Information
Blog 21
fans 0
comment 0
visits 28368
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp实现简单的ajax传值
a张张张浩的博客
Original
1815 people have browsed it
<!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" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<title>无标题文档</title>
</head>
<body>
<input type="text" id="uid" />
<span id="ts"></span>
</body>
<script type="text/javascript">
     
    $("#uid").blur(function(){//blur表示失去焦点时触发
         
        //取用户名
        var uid = $("#uid").val();
         
        //调ajax
        $.ajax({
            url:"__URL__/ajax",
            data:{u:uid},
            type:"GET",
            dataType:"json",
            success: function(data){
                    if(data>0)
                    {
                        $("#ts").html("该应户名已存在");
                        $("#ts").css("color","red");
                    }
                    else
                    {
                        $("#ts").html("该应户名可用");
                        $("#ts").css("color","green");
                    }
                }
             
            });
         
        })
</script>
</html>

上面是我的HTML页面,可以完全复制这个,对应的方法就是意思就是Admin/Index/login

<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    $this->display();
    }
    public function login(){
    	
     $this->display();
    	
    }

    public function ajax(){  
        //ajax传值测试  
         $db=M('user');//这个是实例化user表
         $uid = $_GET["u"];//get方法获取值,我试过post 有可能不成功
         $tj['uname']=$uid;
        $db=$db->where($tj)->count();  
        $this->ajaxReturn($db);  
        $this->display();
    }  
}

上面这个是我用的thinkphp3.2.3的版本的Admin模块,意思就是Admin/Index

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post