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

120
Views
Autocomplete of input field with a lot of data

I am trying to create a search field, searching for cities in Denmark. I have an API with JSON to get all the cities, but there is a lot of data and therefore it takes time to load the page.

Is there any way, that I can load data from this API after the user has typed in the field?

Here is a snipped of the javascript/php I am using to get the data. Here you can see the link of all the cities too.

var cities = [];

            <?

                $citiesData = file_get_contents('https://api.dataforsyningen.dk/steder?hovedtype=Bebyggelse&undertype=by');
                $cityJson = json_decode($citiesData, true);

                for ($x = 0; $x <= count($cityJson) - 1; $x++) {
            ?>
                    cities.push("<? echo $cityJson[$x]["primærtnavn"]; ?>");

            <?
                }
            ?>

After this I am using the autocomplete javascript function from W3School, which can be found here: https://www.w3schools.com/howto/howto_js_autocomplete.asp

How can I make this so it does not take long for the page to load?

about 4 years ago · Juan Pablo Isaza
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!