Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
Retrieve data from JSON file using PHP routine and feed it to html select tag

I'm trying to retrieve data from json file using php and I want this data populated to a html select tag on the front end.

Here is my php file :

<?php

ini_set('display-errors', 'on');
error_reporting(E_ALL);


$executionStartTime = microtime(true);

$result = file_get_contents('countryBorders.geo.json');

$decode = json_decode($result,true);    

$output['status']['code'] = "200";
$output['status']['name'] = "ok";
$output['status']['description'] = "success";
$output['status']['returnedIn'] = intval((microtime(true) - $executionStartTime) * 1000) . " ms";
$output['data'] = $decode;

header('Content-Type: application/json; charset=UTF-8');

echo json_encode($output); 

?>

my main js file :

 $.ajax({
url: "./php/getBorders.php",
type: 'POST',
dataType: "json",

success: function(result) {
    console.log(result);
    
    for (let i=0; i< result.data.border.features.length; i++) {
        $('#selCountry').append($('<option>', {
            value: result.data.border.features[i].properties.iso_a3,
            text: result.data.border.features[i].properties.name,
        }));
       }
    }
});

Currently I'm receiving error that method is not allowed. I'm not sure where I'm making mistake here... If anyone can give me advice I would greatly appreciate it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After checking your answers and digging in little more around my code I found that code below done the job feeding json file data to the html select tag My code snipped below:

$('#selCountry').click(function() {
let border;
let name;
$.ajax({
    url: "./php/getBorders.php",
    type: 'POST',
    dataType: 'json',
    success: function(result) {

        console.log(JSON.stringify(result))

            for (let i=0; i< result.data.border.features.length; i++) {
            $option = $('<option>')
            .val(result.data.border.features[i].properties.iso_a3)
            .text(result.data.border.features[i].properties.name);
    
                     $('#selCountry').append($option);
            }
            const filterData = result.data.border.features.filter((a) => (a.properties.iso_a3 === name));
            border = L.geoJSON(filterData[0]); 
            myMap.fitBounds(border.getBounds());
          
            
        },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(textStatus, errorThrown);
                console.log(jqXHR);
            }
        }); 
    
    });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!