【发布时间】: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