Ayumi
Ayumi
  • 发布:2018-07-04 12:09
  • 更新:2020-03-16 01:28
  • 阅读:3383

mui.ajax报错 error:parsererror

分类:MUI
mui

登陆验证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'=>'请输入用户名或密码!']);
}
}

2018-07-04 12:09 负责人:无 分享
已邀请:
9***@qq.com

9***@qq.com - 前端老菜鸟

请问找到问题了吗?

冰凌桦

冰凌桦

post请求传递参数data不能直接传对象,转成字符串试试:JSON.stringify(params)

3***@qq.com

3***@qq.com

楼主,问题解决了吗,我也遇到了同意的问题

该问题目前已经被锁定, 无法添加新回复