擅长:python、mysql、java
<p>下面的代码应该可以工作</p>
<pre><code>var brand = $('#brand').val()
$.ajax({
type: "POST",
url: "/changeddropdown",
data:{
"brand": brand,
}, success: function (data){
var select = document.getElementById("product_id");
//clear previous data
document.getElementById('product_id').innerText = null;
data.SortByBrand.forEach(function(element, index, list) {
var option = document.createElement('option');
option.text = element.product_name;
option.value = element.product_id
select.add(option, 0);
list[index] = {'name': element};
});
},
})
</code></pre>