javascript - Uncaught TypeError : $. post 不是一个函数

标签 javascript jquery

我在控制台中收到此错误:

Uncaught TypeError: $.post is not a function

对于这段代码:

<script type="text/javascript">
    $('#cl_submit').click(function() { //#cl_submit is a button
        $('#cl_stage1msg').html('Processing...');
        $.post("process/cookie.php", $("#cl").serialize(), function(response) { //#cl is a form
            $('#cl_stage1msg').html(response);
        });
        return false;
    });
</script> <!-- popup included -->

我只是找不到任何错误。为什么这不起作用,有什么线索吗?

但是,$('#cl_stage1msg').html('Processing...'); 工作正常。

似乎只有 post 函数没有被识别。

我正在使用 https://code.jquery.com/jquery-3.1.0.slim.min.js

最佳答案

您正在使用 jQuery 的精简版,它不包含 Ajax 方法(在您的情况下是 $.post() ).

使用非瘦身构建,可在此处获得 http://jquery.com/download/ ,例如:

https://code.jquery.com/jquery-3.5.1.min.js


来自 jQuery 3.0 release post :

Slim build

[...] Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests.[...] Along with the regular version of jQuery that includes the ajax and effects modules, we’re releasing a “slim” version [...], it excludes ajax, effects, and currently deprecated code.

关于javascript - Uncaught TypeError : $. post 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38793723/

相关文章:

javascript - 使用 Javascript 单击按钮或图像时表格列会折叠

javascript - 错误: Uncaught TypeError: Cannot read property 'value' of undefined

javascript - 任意 JS/HTML 上传的 Web 安全

javascript - querySelectorAll 和 getElementsBy* 方法返回什么?

javascript - wordpress jquery 插件并不是一个函数

javascript - 从字符串中提取图像标签

django ajax 查询返回错误 10053 - 已建立的连接被主机中的软件中止

javascript - 在对象中使用 this 时出现 TypeError

jquery - 根据单击的 link_to 渲染部分内容

javascript - jQuery 关闭 Canvas 不工作