<!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
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号