Object # has no method 'done&#

2020-07-14 06:49发布

I was trying to implement simple ajax GET request . In the callback portion i want to call some function . The code is as 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 is showing exception

Uncaught TypeError: Object # has no method 'done' replace_entry.php:105 getCardno replace_entry.php:105 onblur replace_entry.php:118

I am using google chrome

2条回答
迷人小祖宗
2楼-- · 2020-07-14 07:00

You are probably using an old version of jQuery - new versions return a jqXHR object, that does have done.
You can quickly check your version by looking at the source, or typing $().jquery into your console.

If you cannot upgrade, the downgraded code should be:

$.ajax({
      url: "...",
      context: document.body,
      complete: function() { 
           $(this).addClass("done");
      });
查看更多
乱世女痞
3楼-- · 2020-07-14 07:25

Replace the done with success..??

$.ajax({
      url: "<?php echo SITE_URL?>ajax_pages/ajx_getcard.php?id="+obj.value,
      context: document.body
    }).success(function() { 
      $(this).addClass("done");
    });
查看更多
登录 后发表回答