jquery - 浏览器控制台中的 ajax 错误 - 不是函数
问题描述
我不明白为什么我在浏览器控制台中看到它是一个错误。
Uncaught TypeError: $.ajax is not a function - 我看到这条消息
我只发现它不是库的正确版本的建议。但我认为我的版本是正确的。
我的代码
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js"></script>
<input type="button" id="id_name_task" value="Click" />
<script type="text/javascript">
$(document).ready(function() {
$("#id_name_task").click(function() {
var name_task = $(this).val();
console.log(name_task);
$.ajax({
type: 'GET',
async: true,
dataType: 'json',
url: '/validate_data/',
data: {
'name_task': name_task
},
success: function(data) {
if (data.is_taken) {
alert("A task with this name already exists.");
}
},
});
});
});
</script>
解决方案
查看代码我发现 jquery.js 和 jquery.slim.js 之间存在以下差异:
在 jquery.slim.js 中,去掉了以下代码功能:
- jQuery.fn.extend
- jquery.fn.load
- jquery.each // 附上一堆处理常见AJAX事件的函数
- jQuery.expr.filters.animated
- ajax 设置,如 jQuery.ajaxSettings.xhr、jQuery.ajaxPrefilter、jQuery.ajaxSetup、jQuery.ajaxPrefilter、jQuery.ajaxTransport、jQuery.ajaxSetup
- 像 jQuery.parseXML 这样的 xml 解析,
- jQuery.easing、jQuery.Animation、jQuery.speed 等动画效果
$.ajax 从 jQuery slim 3.2.1 中移除
推荐阅读
- python - ValueError:格式错误的节点或字符串
- python - Sklearn set_config 出错
- angular - 带有 mergeMap 的角度异步管道
- sql - 我应该如何在一个表中加入一个字段,该字段已在另一个表中用作 2 个不同字段中的 FK
- compiler-errors - 如何在野牛代码中修复此错误?
- apache-spark - PySpark - 将另一列的值作为 spark 函数的参数传递
- many-to-many - TypeORM 多对多检索所有关系
- c# - 从 URL 读取 XML 属性
- javascript - 在链接悬停时滚动整个页面
- c - 如何在 htons 和 ntohs 中进行铸造?