Andrew2014-04-07 19:15:30
Andrew, 2014-04-07 19:15:30

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

3 answer(s)
Yunus Gaziev, 2014-04-08

<select name="my-select">

// jQuery
var myDynamoSelect = $('select[name="my-select"]');

    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>

look for json - php - ajax information

Nazar Mokrinsky, 2014-04-07

Get the data and insert it into the page.
What exactly are you having problems with?

Insayt, 2014-04-07

Make an ajax request to the server, get new data - and insert it into the select.
for example

// Пусть в res хранится ответ от сервера с данными
$('#id вашего селекта').append('<option>'+res+'</option>');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question