Hello. I try to do so that when a selection is changed in one select , an element is added to another select :
$("#slct").change(function() { var id_prod = $("#slct").val(); $.ajax({ type: 'POST', url: '/admin-panel/specz.php', data: { prod: id_prod } }).then(function(response) { $('#spp').prepend('<option value="1">55555</option>'); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select class="selectpicker show-tick" data-style="btn-white" name="prod" id="slct" required> <option value="1">Не менять</option> <option value="2">Еще один</option> </select> <select class="selectpicker show-tick" data-style="btn-white" name="prod" id="spp" required> <option value="1">Второе</option> </select> But the item does not add.
And if the code is $('#spp').prepend('<option value="1">55555</option>'); separately for the entire structure, the element adds immediately as the page loads.
Although POST goes to the file normally, I even get the answer.
What could be the reason?
then, but throughsuccess? - Yurithenwithsuccess? just tried it - it doesn't add anyway - iKeysuccessadded to the same place asdata.successis a function. (Example:$.ajax({data: {...}, success: function(data) {...}})). This function will be called when a successful response - Yuri