Populating dropdown menu with JSON Data

前端 未结 4 1696
忘了有多久
忘了有多久 2020-12-19 19:49

I\'m tyring to use AJAX to populate a dropdown box based on the selection of another dropdown. I followed a tutorial using jQuery located here - http://remysharp.com/2007/01

4条回答
  •  不知归路
    2020-12-19 19:59

    If you could slightly change your response to return value and text keys in JSON:

    [{
      value: 10,
      text: 'Remy'
    }, {
      value: 11,
      text: 'Arif'
    }, {
      value: 12,
      text: 'JC'
    }]
    

    you could use JQuery view engine and just load the array into a dropdown:

    $.getJSON("contactList", {
        id: $(this).val(),
        ajax: 'true'
      },
      function(j) {
        $("select#QuoteContactId").view(response);
      })
    

    See details here: https://jocapc.github.io/jquery-view-engine/docs/ajax-dropdown

提交回复
热议问题