I have an AJAX request file that looks like this:
$.ajax({
url: 'libs/php/getCountryBorder.php',
type: 'POST',
dataType: 'json',
data: {
name: 'Bahamas',
},
success: function (response) {
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
},
});
I also have a geojson file that looks like this:
You can view my local geojson file here Geojson File
Here is my PHP routine call to the local file geo.json file:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$url = 'https://stephenorowole.co.uk/vendors/countryBorder/countryBorders.geo.json?&name=' . $_REQUEST['name'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
$jsonResponse = json_decode($response, true);
$output['data'] = $jsonResponse['features'];
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($output);
?>
So, I made an Ajax call from another file to the php to get only a specific name in the json file. It doesn't return only the name data but all the data in the json file. What I want is a specific data in the json to be returned through the request. I don't know how to do this with local file. It's easy for me to do if I'm working with external API.
In external API, if a request is made to return only the country that matches a specific latitude and longitude, the specific data will be returned for that specific request. However, I don't know how to achieve this when I'm working with a local file.
I want to be able to get geometry of a country based on the name of the country given as a request data when I make the call. I've just added the ajax call.
Any help will be much appreciated.
