1

I'm working on a registration system using vue & php, on my backend, I want error to stored and return to vue if no error, I want the vue to alert "registration successful".

I got the re-routing right but how do extract the errors from my api response,

in php i have


if(count($error)){
echo $error;
}
 
else {
echo json_encode(["isRegistered"=>true]);

}

in vue I have

data(){
return{
...
data : {// user data goes here},
response : ""
},
}

methods: {
...
axio.post("api/register.php"  data, config)
.then((response) =>{this.response = response.data); 
//the problem
console.log(this.response);
}) ;

}


In only getting Array in my console except when i change

echo $error

to

print_r($error)

in php script

1

1 Answer 1

1

You should return the errors as JSON to make it consistent (and accessible)...

echo json_encode(['errors' => $error]);

You will then at least have access to the errors and you can decide how to display them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.