首页 > 解决方案 > $.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(...) 不是函数

标签: javascriptjqueryajax

解决方案


您尝试将 ajax() 作为函数执行,例如 ajax() ({...}) 这就是您收到错误的原因。

尝试:

function save(){
        $.ajax({
            type: 'POST',
            url: 'file.php',
            data: { name : name, content : content},
            dataType: 'json'
        });
}

推荐阅读