jquery SyntaxError: Unexpected token '< ', "< br /> < b>"... is not valid JSON can someone help me with this? [duplicate]

iaqfqrcu  于 2022-12-22  发布在  jQuery
关注(0)|答案(1)|浏览(646)
    • 此问题在此处已有答案**:

Error with Server SyntaxError: Unexpected token < in JSON at position 1(2个答案)
14小时前关闭。

<?php

$action=$_REQUEST['action'];

if(!empty($action)){
    require_once 'user.php';
    $obj=new user();
}

// adding user action
if($action=='adduser' && !empty($_POST)){
    $name=$_POST['name'];
    $email=$_POST['email'];
    $number=$_POST['number'];
    $address=$_POST['address'];
    $department=$_POST['department'];
    $designation=$_POST['designation'];
    $photo=$_POST['photo'];

    $playerid=(!empty($_POST['userId']))? $_POST['userId']: "";

    $imagename="";
    if(!empty($photo['name'])){
        $imagename=$obj->uploadPhoto($photo);
        $playerData=[
            'name'=>$name,
            'email'=>$email,
            'number'=>$number,
            'address'=>$address,
            'department'=>$department,
            'designation'=>$designation,
            'photo'=>$imagename,
        ];
    }else{
        $playerData=[
            'name'=>$name,
            'email'=>$email,
            'number'=>$number,
            'address'=>$address,
            'department'=>$department,
            'designation'=>$designation,
        ];
    }
    $playerid=$obj->add($playerData);
    
    if(!empty($playerid)){
        $player=$obj->getRow('id',$playerid);
        echo json_encode($player);
        exit(); 
    }
}

?>

我试图通过模态形式将数据填充到数据库中,但无法通过此错误,有人能请让我知道我可以做些什么来克服此问题吗
留言:
"意外标记'〈',"
\n ..."不是有效的JSON"
堆栈:
"语法错误:意外标记'〈',"
\n "..."不是有效的JSON,\n位于解析()\n位于ajaxConvert(http://localhost/phpcrud/jquery.js:9378:19)\n

oxcyiej7

oxcyiej71#

您是否尝试过将true添加到json_encode中?

echo json_encode($player, true);

相关问题