I use select2 for its autocomplete in a select. The problem is that I load a lot of cities in this select, and that makes freeze/lag for my customers which have a bad connection. I’m looking for a script which is able to doawload and autocomplete only when my user is searching a city, rather than load my 60 000 cities from my Database. And idea? Thank you. My code :
<div class="form-group col-md-4">
<label for="Ville">Ville</label>
<input list="ice-cream-flavors" id="ice-cream-choice" name="ice-cream-choice" class="form-control client_ville_insert" />
<datalist id="ice-cream-flavors">
<select type="text" class="form-control">
<?php $list = $bdd->query('SELECT DISTINCT ville_nom FROM ville ORDER BY ville_nom ASC');
while ($data = $list->fetch()) { ?>
<option value="<?php echo $data['ville_nom']; ?>"> <?php echo $data['ville_nom']; ?></option>
<?php } $list->closeCursor(); ?>
</select>
</datalist>
</div>
<div class="form-group col-md-4">
<label for="Postal">Code Postal</label>
<div class="load_postalcode">
Postal Code is load here
</div>