Advertisements
I want to fetch data from database but can’t get it and when I console print it, is just empty.
Is there something wrong with my code?
function har() {
axios.get(url2, {
headers: {
'X-RapidAPI-Key': 'your-rapidapi-key',
'X-RapidAPI-Host': 'body-mass-index-bmi-calculator.p.rapidapi.com',
},
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.error(error);
});
}
This is my my php code
<?php
include 'db.php';
$emparray = array();
$sql = 'SELECT * FROM schedule_list';
$results = mysqli_query($conn,$sql);
while($row = $results->fetch_assoc()){
$emparray[] = $row;
}
$hey = json_encode($emparray)
?>
I just want to get the data from the json encode to javascript without using react or vue, just plain vanilla javascript
>Solution :
You aren’t outputting anything in your server code. Try instead to output the results like:
<?php
include 'db.php';
$emparray = array();
$sql = 'SELECT * FROM schedule_list';
$results = mysqli_query($conn,$sql);
while($row = $results->fetch_assoc()){
$emparray[] = $row;
}
echo json_encode($emparray);
?>