我在控制台中收到此错误:
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 函数没有被识别。
最佳答案
您正在使用 jQuery 的精简版,它不包含 Ajax 方法(在您的情况下是 $.post()
).
使用非瘦身构建,可在此处获得 http://jquery.com/download/ ,例如:
https://code.jquery.com/jquery-3.5.1.min.js
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/