Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: $.post is not a function

I am getting this error in Console:

Uncaught TypeError: $.post is not a function

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.

Seems like only the post function is not getting recognised.

I am using https://code.jquery.com/jquery-3.1.0.slim.min.js

like image 295
Donnie Ashok Avatar asked Aug 05 '16 16:08

Donnie Ashok


2 Answers

You are using the slim version of jQuery, which doesn't include the Ajax methods (in your case $.post()).

Use the non-slim build, available here http://jquery.com/download/, such as:

https://code.jquery.com/jquery-3.5.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.

like image 200
yuriy636 Avatar answered Oct 11 '22 11:10

yuriy636


If you use jquery slim version then this problem will occur. use minified or uncompressed version of jquery js file

like image 22
coder618 Avatar answered Oct 11 '22 10:10

coder618