$('#login').html('登入');
function onLoginClick() {
username = $('input[name=username]').val();
password = $('input[name=password]').val();
$.ajax({
type: "POST",
url: 'http://192.168.18.91/public/index/login/login',
dataType: 'jsonp',
jsonp: 'callback',
data: {username:username,password:password},
success: function(data) {
alert(data.msg);
}
});
}
php
public functionlogin()
{
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$callback=$_GET['callback'];
$pas= md5($password);
$tab= DB::table('tp_admin_user')->where("realname = '{$username}'")->select();
$tab1= DB::table('tp_admin_user')->where("password='{$pas}'")->find();
if($tab==null){
$data=array(
'msg'=>'账号错误'
);
echo$_GET['callback'].'('.json_encode($data).')';
die;
}else if($tab1==null) {
$data=array(
'msg'=>'密码错误'
);
echo$_GET['callback'].'('.json_encode($data).')';
die;
}else{
$data=array(
'msg'=>'成功'
);
echo$_GET['callback'].'('.json_encode($data).')';
die;
}
}
laravel 处理jsonp 跨域请求
先把中间件 csrf 关闭