更新时间:2023-02-01 10:19:27
是的,请检查以下jquery ajax代码. 在此示例中,如果更改部门",则它将填充名称"下拉列表.
Yes, check following jquery ajax code. In this example, if you change "Department" then it will populate the listing of "Name" dropdown.
$(document).on("change", '#department', function(e) {
var department = $(this).val();
$.ajax({
type: "POST",
data: {department: department},
url: 'admin/users/get_name_list.php',
dataType: 'json',
success: function(json) {
var $el = $("#name");
$el.empty(); // remove old options
$el.append($("<option></option>")
.attr("value", '').text('Please Select'));
$.each(json, function(value, key) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
}
});
});