Populating dropdown menu with JSON Data

前端 未结 4 1695
忘了有多久
忘了有多久 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 20:17

    If an array does not start with a 0 index, it is converted into a JSON Object with keys and values instead of an Array. Just use $.each to loop through, grabbing the key (i.e. 1) and the value (i.e. Kieran Hutchinson):

    $(function(){
      $("select#ContactCompanyId").change(function(){
        $.getJSON("contactList",{id: $(this).val(), ajax: 'true'}, function(j){
          var options = '';
          $.each(j, function(key, value){
            options += '';
          })
          $("select#QuoteContactId").html(options);
        })
      })
    })  
    

提交回复
热议问题