【问题标题】:Ajax dropdown not working in django while using adminLTE 3.0.5 template使用 adminLTE 3.0.5 模板时,Ajax 下拉菜单在 django 中不起作用
【发布时间】:2021-01-03 13:19:09
【问题描述】:
【问题讨论】:
标签:
django
ajax
dropdown
adminlte
【解决方案1】:
我已经解决了我的问题。我的问题是我没有在 add_plant.html 文件的内容块中包含以下代码。
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$("#id_country").change(function () {
var url = $("#pForm").attr("data-url_root"); // get the url of the `load_cities` view
var countryId = $(this).val(); // get the selected country ID from the HTML input
console.log(countryId);
$.ajax({ // initialize an AJAX request
url: url, // set the url of the request ? localhost:8000/hr/ajax/load-cities/)
data: {
'country': countryId // add the country id to the GET parameters
},
success: function (data) { // `data` is the return of the `load_cities` view function
$("#id_company").html(data); // replace the contents of the city input with the data that came from the server
}
});
});
</script>
现在我的代码正在运行。
感觉不错。