Javascript 将jquery/ajax集成到django项目时遇到问题
我对编码比较陌生,在django/bootstrap项目中使用jquery/ajax时遇到问题。在标题的开头,我包含了以下代码:Javascript 将jquery/ajax集成到django项目时遇到问题,javascript,jquery,django,ajax,bootstrap-4,Javascript,Jquery,Django,Ajax,Bootstrap 4,我对编码比较陌生,在django/bootstrap项目中使用jquery/ajax时遇到问题。在标题的开头,我包含了以下代码: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> 但是,尝试运行简单函数时: <script> {% block jquery %} var endpoint='/api/data/' $.a
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></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 %}
{%block jquery%}
var endpoint='/api/data/'
$.ajax({
方法:“GET”,
url:endpoint,
成功:功能(数据){
console.log(数据)
},
错误:函数(错误\u数据){
console.log(“错误”)
console.log(错误\u数据)
}
})
{%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)
jquery.min.js:2 jquery.Deferred异常:$.ajax不是函数类型错误:$.ajax不是函数
在HTMLDocument。(http://127.0.0.1:8002/chart/:87:7)
在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)未定义
未捕获的TypeError:$。ajax不是函数
在HTMLDocument。((索引):87)
在e(jquery.min.js:2)
at t(jquery.min.js:2)
我在这里看到的大多数答案似乎都是围绕着安装不包含Ajax的jQuery苗条版本。不过,我相信这里的情况并非如此
非常感谢您的帮助 解决了!事实证明,在添加引导(我很久以前就做过)时,jQuery被导入(放在我的页脚中)。这将我的jQuery常规版本与slim版本改写
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)