2013-09-03 14 views
7

W moim Jquery używam Ajax i otrzymuję komunikat o błędzie poniżej.

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

Zmęczony sukcesem zamiast gotowym. ale wciąż otrzymuję ten sam komunikat.

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

przykładowy fragment kodu jest wymienione poniżej:

$(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); 
     }); 
+5

czy załadowany jQuery .. ?? jakiej wersji jquery używasz ..? –

+1

spróbuj użyć najnowszej wersji jquery i użyj .done, powinien zadziałać –

Odpowiedz

10

zastąpić success z done lub użyj sukcesu wewnątrz funkcji ajax.

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); 
      } 
     }); 
}); 
3

spróbować użyć funkcji sukcesu wewnątrz funkcji ajax,

$(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); 
      } 
     }); 
}); 
0

success i error nie są atrybutami obiektu zwróconego przez zadzwoń pod numer $.ajax(). Zamiast tego, należy przekazać je jako configs w zaproszeniu:

$.ajax({..., success: function(data){}}) 
1

Można stosować tę Demo

Istnieje kilka dodatkowych funkcji, które pomogą Ci

Nice 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);      
     } 
     ); 

} 
); 
+0

to pozwala ci wystrzelić jakąś dodatkową funkcję przed, po, wyniku sukcesu ............ –

Powiązane problemy