Object # <XMLHttpRequest> does not have a 'done' method

I tried to implement a simple ajax GET request. In the callback part, I want to call some function. Code below

$.ajax({
          url: "<?php echo SITE_URL?>ajax_pages/ajx_getcard.php?id="+obj.value,
          context: document.body
        }).done(function() { 
          $(this).addClass("done");
        });

But it shows an exception

Uncaught TypeError: Object # does not have a 'done' method replace_entry.php: 105 getCardno replace_entry.php: 105 onblur replace_entry.php: 118

I am using google chrome

+5
source share
2 answers

You are probably using the old version of jQuery - new versions return the jqXHR object that it has done.
You can quickly check your version by looking at the source or typing $().jqueryin your console.

If you cannot update, the reduced code should be:

$.ajax({
      url: "...",
      context: document.body,
      complete: function() { 
           $(this).addClass("done");
      });
+17

..??

$.ajax({
      url: "<?php echo SITE_URL?>ajax_pages/ajx_getcard.php?id="+obj.value,
      context: document.body
    }).success(function() { 
      $(this).addClass("done");
    });
0

All Articles