javascript - MUI,ajax错误 Unexpected token <

查看:334
本文介绍了javascript - MUI,ajax错误 Unexpected token <的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

MUI,ajax错误SyntaxError: Unexpected token <

ajax 抛出一个这样的错误是什么意思?

**SyntaxError: Unexpected token <
    at Function.parse [as parseJSON] (native)
    at XMLHttpRequest.u.onreadystatechange** 

前端js

    mui.ajax({
                data:accInfo,
                url:"/dologin",
                // contentType: "application/x-www-form-urlencoded;charset=utf-8",//这个头信息的含义?
                type:'POST',
                // timeout:1000,
                dataType:"json",
                success:function(data){
                    console.log("返回成功:\n");
                    console.log(data);
                    if(data=='success'){
                        window.location.href="/alarm2";
                    }else{
                        console.log("登出失败");
                    }
                },
                error:function(xhr, type, errorThrown) {
                    //异常处理;
                console.log(xhr);
                console.log(type);
                **console.log(errorThrown);**//SyntaxError: Unexpected token <
                }
            });


后端js
router.post('/dologin',function(req,res,next){
    var user={
        account:"user",
        password:"pass"
    }
    console.log(req.body);
    if(req.body.account=='user'&&req.body.password=='pass'){
        req.session.userid=req.body.account;
        console.log('成功');
        // res.send("success");
        res.redirect('/alarm2');//跳转
        
    }else{
        console.log('账户或密码错误');
        res.redirect('/');
//        res.send("false")
    }
});

解决方案

已经知道了,是json格式问题,前台定义了json 但后台返回的是String 从因此有错误。所以将后台返回的数据设为json格式即可

这篇关于javascript - MUI,ajax错误 Unexpected token &lt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆