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

In my jQuery, I use Ajax and get below msg error message.

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

I was tired of success, not doing it. but still getting the same messages.

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

An example code snippet is shown 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); }); 
+7
javascript jquery ajax
source share
4 answers

Replace success with done or use success in the ajax function.

An alternative construct for the success callback option .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); } }); }); 
+10
source share

try using success function inside ajax function,

  $(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); } }); }); 
+3
source share

You can use this demo

There is an additional feature that will help you.

Good demo

  $( function(){ // Get a reference to the content div (into which we will load content). var jContent = $( "#content" ); // Hook up link click events to load content. $( "a" ).click( function( objEvent ){ var jLink = $( this ); // Clear status list. $( "#ajax-status" ).empty(); // Launch AJAX request. $.ajax( { // The link we are accessing. url: jLink.attr( "href" ), // The type of request. type: "get", // The type of data that is getting returned. dataType: "html", error: function(){ ShowStatus( "AJAX - error()" ); // Load the content in to the page. jContent.html( "<p>Page Not Found!!</p>" ); }, beforeSend: function(){ ShowStatus( "AJAX - beforeSend()" ); }, complete: function(){ ShowStatus( "AJAX - complete()" ); }, success: function( strData ){ ShowStatus( "AJAX - success()" ); // Load the content in to the page. jContent.html( strData ); } } ); // Prevent default click. return( false ); } ); } ); 
+1
source share

success and error are not attributes of the object returned by calling $.ajax() . Instead, you should pass them as configs in the call:

 $.ajax({..., success: function(data){}}) 
0
source share

All Articles