Answer the question
In order to leave comments, you need to log in
Ajax and dynamic select - how to implement?
! Everything is implemented in php + mysql.
There is a select with an option set, the values for which are unloaded from the database.
While the user is browsing the page, the data in the select can be added. How, without reloading the page completely, but simply by clicking on a certain button, you can update the data in the select?
Thanks in advance for your help.
Answer the question
In order to leave comments, you need to log in
<select name="my-select">
<option>...</option>
<option>...</option>
<option>...</option>
</select>
// jQuery
var myDynamoSelect = $('select[name="my-select"]');
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function ( data ) {
// empty() чистим HTML в селект
// html(data) вставляем в select то что ответил сервер (<option>...</option>)
// пример ответа: <option>...</option><option>...</option><option>...</option>
myDynamoSelect.empty().html(data);
}
});
Get the data and insert it into the page.
What exactly are you having problems with?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question