0

I do not understand why I see it an error in the browser console.
Uncaught TypeError: $.ajax is not a function - I see this message

enter image description here

I only found advice that it is not the correct version of the library. But I think my version is correct.
My code

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js"></script>
<input type="button" id="id_name_task" value="Click" />


<script type="text/javascript">
  $(document).ready(function() {
    $("#id_name_task").click(function() {
      var name_task = $(this).val();
      console.log(name_task);
      $.ajax({
        type: 'GET',
        async: true,
        dataType: 'json',
        url: '/validate_data/',
        data: {
          'name_task': name_task
        },
        success: function(data) {
          if (data.is_taken) {
            alert("A task with this name already exists.");
          }

        },
      });
    });
  });
</script>
empiric
  • 7,825
  • 7
  • 37
  • 48
Serhii
  • 1,367
  • 3
  • 13
  • 31
  • 1
    I don't understand either, the code you posted works (request is actually blocked by CORS in snippet, but it is sent correctly). Something else in your code is probably interfering with this part. We currently have not enough information to solve your problem.. – Kaddath May 18 '18 at 08:19
  • Any conflict with another library using the `$` sign? – empiric May 18 '18 at 08:21
  • The snippet I made for you seems to work - perhaps you load more than one jQuery? – mplungjan May 18 '18 at 08:21

1 Answers1

0

Looking at the code I found the following differences between jquery.js and jquery.slim.js:

In the jquery.slim.js, the following function of code are removed:

  1. jQuery.fn.extend
  2. jquery.fn.load
  3. jquery.each // Attach a bunch of functions for handling common AJAX events
  4. jQuery.expr.filters.animated
  5. ajax settings like jQuery.ajaxSettings.xhr, jQuery.ajaxPrefilter, jQuery.ajaxSetup, jQuery.ajaxPrefilter, jQuery.ajaxTransport, jQuery.ajaxSetup
  6. xml parsing like jQuery.parseXML,
  7. animation effects like jQuery.easing, jQuery.Animation, jQuery.speed

What are the differences between normal and slim package of jquery?

$.ajax is removed from jQuery slim 3.2.1

Vel
  • 9,027
  • 6
  • 34
  • 66