【问题标题】: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 项目使用 adminlte3 主题。在这个项目中,我有一个带有 ajax 相关下拉控件的表单。在添加工厂表单中,此下拉列表(公司)将根据国家/地区的选择进行填充。但是当我使用 adminlte3 模板时它不起作用。 请查看 github 链接。 https://github.com/shahidpharm/qtrack

谁能帮帮我?

谢谢

【问题讨论】:

    标签: 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>
    
    

    现在我的代码正在运行。 感觉不错。

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 1970-01-01
      • 2017-06-12
      • 2020-07-13
      • 1970-01-01
      • 2017-05-15
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多