javascript - $.ajax(...) 不是函数
问题描述
即使我使用常规版本的 jquery 我也有问题
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="https://code.jquery.com/jquery-3.5.1.min.js"><\/script>')</script>
html:
<button class="btn btn-secondary" type="button" id="save" onclick="save()">save</button>
ajax函数:
function save(){
$.ajax() ({
type: 'POST',
url: 'file.php',
data: { name : name, content : content},
dataType: 'json'
});
}
未捕获的类型错误:$.ajax(...) 不是函数
解决方案
您尝试将 ajax() 作为函数执行,例如 ajax() ({...}) 这就是您收到错误的原因。
尝试:
function save(){
$.ajax({
type: 'POST',
url: 'file.php',
data: { name : name, content : content},
dataType: 'json'
});
}
推荐阅读
- python - 包括记录器类的对象清单类覆盖字典条目
- sql - 使用内部连接更新表
- redirect - 在 Razor 页面中重定向到带有 ID 的页面
- google-sheets - 更新文件夹和子文件夹中所有文件中的单个工作表
- android - Android 移动应用程序可绘制图标下载
- bootstrap-4 - Bootstrap 4手风琴不会自动关闭以前打开的部分
- javascript - 混合内容:HTTP 问题
- c# - 根据 Entity Framework Core 中的不同列选择所有行
- json - 如何将 JSON 提交到 PowerShell RestMethod 或 WebRequest
- ruby - 是否可以覆盖接收器行为?