Thinkphp+Jquery Login Demo
昨天晚上和一个同学开玩笑说感觉刘翔这次不会拿金牌,只是一种直觉。
今天,刘翔退出了比赛……
开始了最痛苦的征程,没有任何的理由,留下的是永远的遗憾。
主持人说了一句经典的话:一个人的精神可以是铁打的,但人是不可能是铁打的。
到底精神是基础还是人的本身呢?没有了精神的躯体还叫身体吗?没有了身体的精神只能"留取丹心照汗青"。
(废话说多了^_^ , 下面开始正题)
初次接触jquery和Thinkphp , 心血来潮就结合这两个做了个登陆的例子 :
页面代码:
<div align="center">
<p>用户名:
<input type="text" name="lid" id="lid" />
</p>
<p>密码:
<input type="text" name="pwd" id="pwd" />
</p>
<p>
<input type="submit" name="loginbt" id="loginbt" value="登 陆" />
</p>
<p><div id="state" name="state"></div></p>
</div>
<p>用户名:
<input type="text" name="lid" id="lid" />
</p>
<p>密码:
<input type="text" name="pwd" id="pwd" />
</p>
<p>
<input type="submit" name="loginbt" id="loginbt" value="登 陆" />
</p>
<p><div id="state" name="state"></div></p>
</div>
Javascript代码:(有两种方法)
$(document).ready(function(){
$('#loginbt').click(function(){
// case one :
$.ajax({
type:"POST",
url:"../index.php/index/doAjax",
data:{lid:$('#lid').val(),pwd:$('#pwd').val()},
success:function(msg){
$('#state').html(msg);
}
});
// case two:
/*
$.post("../index.php/index/doAjax",{lid:$('#lid').val(),pwd:$('#pwd').val()},function(msg){
$('#state').html(msg);
});
*/
});
});
$('#loginbt').click(function(){
// case one :
$.ajax({
type:"POST",
url:"../index.php/index/doAjax",
data:{lid:$('#lid').val(),pwd:$('#pwd').val()},
success:function(msg){
$('#state').html(msg);
}
});
// case two:
/*
$.post("../index.php/index/doAjax",{lid:$('#lid').val(),pwd:$('#pwd').val()},function(msg){
$('#state').html(msg);
});
*/
});
});
后台php代码:
class IndexAction extends Action
{
public function index()
{
}
public function doAjax()
{
$lid=$_POST["lid"];
$pwd=$_POST["pwd"];
if($lid==""||$pwd=="")
echo '用户名或密码为空!';
else
{
if($lid=="admin" && $pwd=="admin")
echo '登陆成功!';
else
echo '登陆失败!';
}
}
}
{
public function index()
{
}
public function doAjax()
{
$lid=$_POST["lid"];
$pwd=$_POST["pwd"];
if($lid==""||$pwd=="")
echo '用户名或密码为空!';
else
{
if($lid=="admin" && $pwd=="admin")
echo '登陆成功!';
else
echo '登陆失败!';
}
}
}
如果有什么疑问 , 请留言 , 谢谢您浪费时间来' 收看 ' ~