Dropdown populate ajax

后端 未结 2 1436
既然无缘
既然无缘 2020-12-11 23:42

I have the following issue: When i select an element from a drop down i want to auto populate another drop down via ajax. the idea is that the subcategory(sub_type) doesn\'t

2条回答
  •  失恋的感觉
    2020-12-12 00:09

    The problem is, that you are assigning the html to #sub_type right after the ajax JSON call. You should assign it in the ajax callback function like this:

    $("#type").change(function(){
      $.getJSON("ajax/add_subcathegory.php",{id: $(this).val(), ajax: 'true'}, function(j){
        var options = '';
        for (var i = 0; i < j.length; i++) {
          options += '';
        }
        $("#sub_type").html(options);
      });    
    });
    

提交回复
热议问题