How to reload a SELECT in a form, using ajax via jQuery
Hello,
firstofall, sorry, i know that it's a simple question (maybe stupid) but i cannot find out how to do.
1) a user on the website popup add an element to the Database using $.post
WORKING
2) i want to refresh the SELECT in the form to include his element that the user just added without reload the page. Don't know how to do that.
- <select id="wheel" name="wheel">
- <?php
- $connection = new DBConnection();
- $requete = "SELECT nomService FROM structures WHERE serviceInterne = 0";
- $result = $connection->query($requete);
- while($val = mysql_fetch_array($result)) {
- $servicesExternes = $val['nomService'];
- print '<option value='.$servicesExternes.'>'.$servicesExternes.'</option>';
- }
- $connection -> end();
- ?>
- </select>
And here the .js
- $(document).ready(function(){
- $('#valider_ajout_structure').click(function(){
var nomStructure = $('#nomStructure').val();
var ajouterStructureInterne = $('#ajouterStructureInterne').val();
if (nomStructure.length == 0)
{
$('.jquery').html('<class="erreur">Vous n\"avez pas rentré le nom de la structure');
}
else
{
$.post("/Iseult/ajouter/structure.php", { nomStructure : nomStructure, ajouterStructureInterne:ajouterStructureInterne });
- I guess the code to update the SELECT will be here :p
}
});
});
Thanks for your help