I must display data that i set in my user model, I get the info from the database but encode in html format.
I have already tried a lot of things like deserialize my json to put in the right format but I still have the output in pure html.
public function ReadUserData($action) {
if (strcmp($action, "read") == 0) {
global $f3;
$user = $this->db->exec("SELECT
users.username,
users.email,
users.mobile
FROM
users");
return json_encode($user);
}
}
and in my vue js i have :
methods : {
getDataUsers: function() {
axios.get("http://localhost/?action=read")
.then(function(response) {
if (response.data.error) {
app.errorM = response.data.message;
} else {
//app.users = response.data.users;
app.users = "{{ @users }}";
console.log(app.users);
}
});
}
}
Actually my output is in html format :/
[{"username":"toto","email":"toto@gmail.com","mobile":"0676565443"},{"username":"jojo","email":"jojo@gmail.com","mobile":"0678654534"},{"username":"jojo","email":"jojo@gmail.com","mobile":"0678654534"}]
" where replace by " :/
I was thinking if it was possible to directly loop through the method and replace the "& quot" with real double quotes ?
Than'ks for your time !
You must return json header from backend:
header('Content-Type: application/json');
echo json_encode($data);
And accept json in front end:
axios.post("/", {
headers: {
'Content-Type': 'application/json'
},
data
})