Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting TypeError: $.ajax(...).done is not a function [Ajax, Jquery ]

In my Jquery, i am using Ajax and getting below error msg.

TypeError: $.ajax(...).done is not a function
[Break On This Error] ).success(function(response) {

I tired using success instead of done. but still getting same msg.

TypeError: $.ajax(...).success is not a function
[Break On This Error] ).success(function(response) { 

sample piece of code is mentioned below:

$(document).ready(function () {
        alert('in get');
        $.ajax({
            data: {
                'contentId': contentId,
                'USER_ID': USER_ID,
                'actionType': 'GETRATING',
                'portletGuid': portletGuid
            },
            type: 'GET',
            url: ajaxRatingServlet,
            cache: false
        }).success(function (response) {
            getUserPreference(response);
        });
like image 505
Shailendra Kumar Avatar asked Sep 03 '13 09:09

Shailendra Kumar


1 Answers

Replace your success with done or use success inside ajax function.

An alternative construct to the success callback option, the .done() method replaces the deprecated jqXHR.success() method.

EG

$(document).ready(function () {
    $.ajax({
        data: {
            'contentId': contentId,
            'USER_ID': USER_ID,
            'actionType': 'GETRATING',
            'portletGuid': portletGuid
        },
        type: 'GET',
        url: ajaxRatingServlet,
        cache: false
    }).done(function (response) {
        console.log(response);
  });

 //or use success inside ajax as other answered

 $(document).ready(function() {
      alert('in get'); 
      $.ajax({ 
       data: { 'contentId':contentId, 'USER_ID':USER_ID, 'actionType':'GETRATING', 'portletGuid':portletGuid },
       type:'GET',
       url:ajaxRatingServlet,
       cache:false,
       success: function(response) { 
            getUserPreference(response);
           }
      });
 }); 
like image 172
Konsole Avatar answered Oct 20 '22 00:10

Konsole