Dropdown populate ajax

后端 未结 2 1443
既然无缘
既然无缘 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:26

    Assuming that the Ajax success function is indeed called, change the function code to:

              var $subType = $("#sub_type");
              $subType.empty();
              $.each(j, function () {
                $subType.append($('').attr("value", this.id).text(this.name));
              });
    

    Your main problems currently are:

    • the html function is called only once because it's outside of the sucess function.
    • the elements in the Ajax data have the keys id and name and not optionValue and optionDisplay

    Update:

    The returned JSON is invalid. String have to be quoted with double quotes, not single quotes. As a result, the getJSON() call fails silently.

提交回复
热议问题