Uncaught TypeError: $ .ajax is not a function?

2

What problem with my code, in the console shows this error:

home:85 Uncaught TypeError: $.ajax is not a function
        at HTMLFormElement.<anonymous> (home:85)
        at HTMLFormElement.dispatch (jquery-3.2.1.slim.min.js:3)
        at HTMLFormElement.q.handle (jquery-3.2.1.slim.min.js:3)

Searching for found this in SoEn :

My javascript code

<script type="text/javascript">
          $(function() {
            $('#login-form').submit(function(e) {
              e.preventDefault(), $('#btn-login').html('Autenticando...');

              var username = $('#username').val();

              if (/^[a-zA-Z0-9_ ]*$/.test(username)) {
                $('.form-message').css('display', 'block'),
                $('.message').html('Existem caracteres especiais no seu usuário. Se estiver usando <strong>"@"</strong>, remova-o!');

                return false;
              }

              $.ajax({
                type: 'POST',
                data: $(this).serialize(),
                success: function(s) {
                  alert('ok');
                }
              });
            });
          });
        </script>
    
asked by anonymous 22.08.2017 / 22:42

1 answer

3

Boys, I found the error in this line:

if (/^[a-zA-Z0-9_ ]*$/.test(username)) 

I changed to

if (0 == /^[a-zA-Z0-9_ ]*$/.test(username)) 

Remembering version slim of jquery does not have $.ajax({})

Reference

  

Sometimes you do not need ajax, or you prefer to use one of the many   standalone libraries that focus on ajax requests. And often it is   simpler to use a combination of CSS and class handling for all   your web animations. Along with the regular version of jQuery that   includes the ajax and effects modules, we've released a "slim" version   that excludes these modules. The size of jQuery is very rarely a load   performance concern these days, but the slim build is about 6k gzipped   bytes smaller than the regular version - 23.6k vs 30k. These files are   also available in the npm package and on the CDN:

    
22.08.2017 / 22:49