I had this project worked in the past but I have been studying and working on the UX/UI for the past 8 months so I have not been programming the backend since. Now I'm back to do some editing on this project again but why won't json_encode() print the object as array like it used to? It now just print the whole page of that php file instead.
I feel I need to refresh my memory again.
See the php/countryCodeAndName.php code below;
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$executionStartTime = microtime(true);
// Read JSON file
$json = file_get_contents('../vendors/countryBorders.geo.json');
//Decode JSON
$json_data = json_decode($json,true);
//Print data
$nameAndISO = $json_data["features"];
for ($i = 0; $i < count($nameAndISO); $i++) {
$name[] = $nameAndISO[$i]["properties"]["name"];
$iso[] = $nameAndISO[$i]["properties"]["iso_a3"];
}
$output["name"] = $name;
$output["iso"] = $iso;
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($output);
?>
Below is my js file where I used Ajax to get the data but as I've stated, it just print the whole php syntax instead of encoding the array...
$.ajax({
type: "GET",
url: "libs/php/countryCodeAndName.php",
success: function(data) {
console.log(data)
}
})
This project is running on XAMPP where all starts + mount lampp/htdocs/...