Home  >  Q&A  >  body text

What is returned is not in json format

return ['status'=>$status,'message'=>$result, 'data'=>$data];

乌鸦乌鸦2466 days ago1658

reply all(2)I'll reply

  • 乌鸦

    乌鸦2017-12-23 11:28:12

    This is written based on the video, and it is written like this in the video.

    Server-side code:

    public function checkLogin(Request $request)
    {
    echo "Enter the login verification method";
    //Initial return parameters
    $status = 0;
    $result = 'sdasdas';
    $data = $request->param();

    return ['status'=>$status,'message '=>$result, 'data'=>$data];
    }

    jq's ajax code:

    $.ajax({
    type:"post ",
    url:"{:url('checkLogin')}",
    data:{user:username,pwd:password,sf:shenfen,xt:xitong},
    dataType:"json" ,
    success:function(res){
     alert("Execution successful"+res);
    },error:function(){
     alert("jadhasjdhajlsk")
    }
    })

    The front end will finally display: jadhasjdhajlsk

    reply
    0
  • iamyl

    iamyl2017-12-23 06:20:44

    The JSON format is text, and it is echoed out. Yours is a return, and it is an array. How can it be JSON? You need to use json_decode(array); to convert the array into text, so that the front end can get json

    reply
    0
  • Cancelreply