Home > Back-end >  Axios always return string and missing last two characters
Axios always return string and missing last two characters

Time:06-16

I am facing a problem with axios post.

  public function viewAuthCheck(Request$request){


        return [ 'test' => 'hello!' ];
    }

my axios function

axios.post('/timetracking/settings/auth/check/user', {
                    auth_check:this.auth_check_list

                }).then(response => {
                    console.log(response.data);
                });

and the output always returns string and missing last two characters enter image description here

CodePudding user response:

first

you should return as json like this:

return response()->json(['test'=>'hello!']);

and when you access it by axios

console.log(response.data.test);

CodePudding user response:

Try return response()->json(['test' => 'hello!'])

  • Related