【问题标题】:Trouble integrating jquery/ajax into django project无法将 jquery/ajax 集成到 django 项目中
【发布时间】:2020-04-04 15:37:19
【问题描述】:

我对编码比较陌生,并且在让 jquery/ajax 在我的 django/bootstrap 项目中工作时遇到问题。在标题的开头,我包含了以下代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

但是,当尝试运行一个简单的函数时:

<script>
{% block jquery %}
var endpoint='/api/data/'

$.ajax({
    method: 'GET',
    url: endpoint,
    success: function(data){
        console.log(data)
    },
    error: function(error_data){
        console.log("error")
        console.log(error_data)
    }
})


{% endblock %}

我一直在控制台中显示相同的两个错误:

jquery.min.js:2 jQuery.Deferred exception: $.ajax is not a function TypeError: $.ajax is not a function
at HTMLDocument.<anonymous> (http://127.0.0.1:8002/chart/:87:7)
at e (https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js:2:29453)
at t (https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js:2:29755) undefined

Uncaught TypeError: $.ajax is not a function
at HTMLDocument.<anonymous> ((index):87)
at e (jquery.min.js:2)
at t (jquery.min.js:2)

我在这里看到的大多数答案似乎都围绕着安装不包含 Ajax 的精简版 jQuery。但是,我相信这里不是这样的。

非常感谢任何帮助!

【问题讨论】:

    标签: javascript jquery django ajax bootstrap-4


    【解决方案1】:

    解决了!事实证明,当添加引导程序(我很久以前做过)时,会导入 jQuery(放在我的页脚中)。这用超薄版本覆盖了我的常规 jQuery 版本。

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 2016-01-20
      • 2011-09-22
      • 2021-08-12
      • 2017-02-22
      • 1970-01-01
      相关资源
      最近更新 更多