Javascript 未捕获的类型错误:$.post 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38793723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: $.post is not a function
提问by Donnie Ashok
I am getting this error in Console:
我在控制台中收到此错误:
Uncaught TypeError: $.post is not a function
未捕获的类型错误:$.post 不是函数
for this piece of code:
对于这段代码:
<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 -->
I just couldn't find anything wrong in this. Why is this not working, any clues?
我只是找不到任何错误。为什么这不起作用,任何线索?
However, $('#cl_stage1msg').html('Processing...');
is working fine.
但是,$('#cl_stage1msg').html('Processing...');
工作正常。
Seems like only the post function is not getting recognised.
似乎只有 post 功能没有得到认可。
回答by yuriy636
You are using the slim versionof jQuery, which doesn't have AJAX(in your case the $.post()
function).
您正在使用jQuery的精简版,它没有 AJAX(在您的情况下是$.post()
函数)。
Use the non-slim build, available here http://jquery.com/download/, such as:
使用non-slim build,可在http://jquery.com/download/ 处获得,例如:
https://code.jquery.com/jquery-3.3.1.min.js
https://code.jquery.com/jquery-3.3.1.min.js
From 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.
苗条身材
[...] 有时您不需要 ajax,或者您更喜欢使用许多专注于 ajax 请求的独立库之一。[...] 连同包含 ajax 和效果模块的 jQuery 常规版本,我们正在发布一个“slim”版本 [...],它不包括 ajax、效果和当前已弃用的代码。
回答by Ahadul islam
If you use jquery slim version then this problem will occur. use minified or uncompressed version of jquery js file
如果使用 jquery slim 版本,则会出现此问题。使用缩小或未压缩版本的 jquery js 文件