Using jQuery, JSON and AJAX to populate a drop down

后端 未结 2 758
长情又很酷
长情又很酷 2021-01-22 21:33

like the title says, I am trying to create a drop down menu using jQuery, JSON and AJAX, although I am familiar with the theory I have yet to put it into practice, any advice, d

2条回答
  •  被撕碎了的回忆
    2021-01-22 21:52

    This should do the trick:

    $.getJSON("test.php", function(data){
      $.each(data, function(index, text) {
        $('#mySelect').append(
            $('').val(index).html(text)
        );
      });
    });
    

    note: test.php should return an json encoded array

提交回复
热议问题