为什么我用thinkphp和jquery的ajax提交前端没反应 10
js代码:<script>$(function(){$('#sub_btn').click(function(){varadminname=$(".username")....
js代码:
<script>
$(function(){
$('#sub_btn').click(function(){
var adminname = $(".username").val();
var adminpassword = $(".pwd").val();
$.post('/demo//Home/Adminlogin/logincheck',
{name:adminname,password:adminpassword},
'json',
function(date,status){
if(date.status==1){
alert('登录成功');
}
else{
alert('用户名和密码不正确');
}
});
})
})
</script>
控制器代码:
class AdminloginController extends Controller {
public function index(){
$this->display('Index/adminlogin');
}
public function logincheck(){
$admin=M('Admin');
$condition['admin_name']=$_POST('name');
$condition['admin_password']=$_POST('password');
$result=$admin->where($condition)->select();
if ($result) {
$dataReturn['status']=1;
$dataReturn['info']='success';
$this->ajaxReturn($dataReturn,'json');
}else{
$dataReturn['status']=0;
$dataReturn['info']='error';
$this->ajaxReturn($dataReturn,'json');
}
} 展开
<script>
$(function(){
$('#sub_btn').click(function(){
var adminname = $(".username").val();
var adminpassword = $(".pwd").val();
$.post('/demo//Home/Adminlogin/logincheck',
{name:adminname,password:adminpassword},
'json',
function(date,status){
if(date.status==1){
alert('登录成功');
}
else{
alert('用户名和密码不正确');
}
});
})
})
</script>
控制器代码:
class AdminloginController extends Controller {
public function index(){
$this->display('Index/adminlogin');
}
public function logincheck(){
$admin=M('Admin');
$condition['admin_name']=$_POST('name');
$condition['admin_password']=$_POST('password');
$result=$admin->where($condition)->select();
if ($result) {
$dataReturn['status']=1;
$dataReturn['info']='success';
$this->ajaxReturn($dataReturn,'json');
}else{
$dataReturn['status']=0;
$dataReturn['info']='error';
$this->ajaxReturn($dataReturn,'json');
}
} 展开
2个回答
展开全部
$.post('/path/to/file', {param1: 'value1'}, function(data) {
/*optional stuff to do after success */
},'json');
public function logincheck(){
$admin=M('Admin');
$condition['admin_name']=I('name');//$_POST['name'];
$condition['admin_password']=I('password'); //这个要加密的
$result=$admin->where($condition)->find();
if ($result) {
$this->success('登录成功',U('/index'));
}else{
$this->error('登录失败');
}
}
/*optional stuff to do after success */
},'json');
public function logincheck(){
$admin=M('Admin');
$condition['admin_name']=I('name');//$_POST['name'];
$condition['admin_password']=I('password'); //这个要加密的
$result=$admin->where($condition)->find();
if ($result) {
$this->success('登录成功',U('/index'));
}else{
$this->error('登录失败');
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询