Why am I getting Uncaught TypeError: $ .ajax is not a function?

  • 0
    Hello. I get an error in the script. Googled, everyone writes that the error is due to the slim library, but I have
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


    I'm trying to work out this script.
    <script src="{% static 'js/reconnecting-websocket.js' %}"></script>
        <script>
    
    function selectFile() {
    	e = document.getElementById('upload')
      if(e.files[0]) {
        let item = e.files[0];
        let filesize = item.size;
        let filesizeMB = (filesize / (1024 * 1024)).toFixed(2);
        if (filesizeMB >= 3) {
          alert('Максимальный размер фотографии 3 мб');
        } else {
          let form = new FormData();
          form.append('image_message', item);
          form.append('room_id', {{ room_name_json }});
          form.append('user_id', {{ username }});
            $.ajax({
                url: '/chat/upload/',
                type: "POST",
                data: form
            });
        }
      } else {
        alert('Файл не найден');
      }
    }
    </script>

    If you just type console.log ($. Ajax); it finds it function ajax (t, n)
    How can you fix it?
    JavaScript Anonymous, Jan 6, 2020

  • 2 Answers
  • 0
    Perhaps the function is called before $ is connected
    Nora Ochoa

  • 0
    Replace

    $.ajax({
    url: '/chat/upload/',
    type: "POST",
    data: form
    });




    jQuery.ajax({
    url: '/chat/upload/',
    type: "POST",
    data: form
    });
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!