首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用adminLTE 3.0.5模板时,Ajax下拉菜单在django中不起作用

使用adminLTE 3.0.5模板时,Ajax下拉菜单在django中不起作用
EN

Stack Overflow用户
提问于 2021-01-03 21:19:09
回答 1查看 96关注 0票数 0

我正在使用adminlte3主题为我的姜戈项目。在这个项目中,我有一个表单与ajax依赖下拉控件。在添加工厂表单中,此下拉列表(公司)将根据国家/地区的选择进行填充。但是当我使用adminlte3模板时,它不工作。请参阅github链接。https://github.com/shahidpharm/qtrack

有谁可以帮我?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2021-01-04 18:11:30

我已经解决了我的问题。我的问题是我没有在add_plant.html文件的内容块中包含下面的代码。

代码语言:javascript
运行
复制
<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>

现在我的代码可以工作了。感觉很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65550291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档