I'm making a map using leaflet.js right now I'm getting countries through a json file using php as data provider and sending the ajax request to get data
PHP that provides File:
<?php
header("Access-Control-Allow-Origin: *");
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$data=file_get_contents("capitals.geojson");
$data= json_decode($data, true);
$data2= $data["features"];
echo json_encode($data2);
?>
Ajax Request that is getting data from php file:
$.ajax({
url: "php/capitals.php",
type: 'GET',
dataType: 'json',
success: function(result) {
countryList=result;
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error");
}
});
Right now I'm choosing a specific object using this code:
option.value="GB";
const selectedCountry = countryList.find( countryObj => countryObj.id === option.value);
console.log(selectedCountry);
Instead of getting specific object from this code I want to get it from the PHP routine so that when an ajax request is passed the file returns only the specific object that I need.
I tried getting the specific object from json file using javascript but I want to get it through PHP.