登陆验证mui.ajax 一直报错 error:parsererror
后台返回是json格式没错啊,但app前端一直报错 parsererror
登陆js:
mui.ajax(owner.baseUrl+'login/',{
data:{
username: loginInfo.account,
password: loginInfo.password,
clientid: clientid
},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},
success:function(data){
//服务器返回响应,根据响应结果,分析是否登录成功;
if(data.status==true){
owner.createState(loginInfo.account, callback, data.access_token, data.user_id);
}
if(data.status==false)
{
return callback(data.msg);
}
},
error:function(xhr,type,errorThrown){
//异常处理;
console.log('error:'+type);
callback('服务器繁忙,请稍后再试。')
}
});
后端login.php:
//header("Content-Type:text/html; charset=utf-8");
header('Content-type:application/json');//输出为json格式页
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
class LoginController extends AppBaseController
{
public function index()
{
return json(['status'=>true,'msg'=>'请输入用户名或密码!']);
}
}