2013-09-03 7 views
7

मेरी Jquery में, मैं अजाक्स का उपयोग कर रहा हूं और त्रुटि संदेश नीचे आ रहा हूं।

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

मैं किए जाने की बजाय सफलता का उपयोग करके थक गया। लेकिन अभी भी एक ही संदेश मिल रहा है। कोड की

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

नमूना टुकड़ा नीचे वर्णित है:

$(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

आप jQuery लोड किया है .. ?? आप किस jquery का उपयोग कर रहे हैं ..? –

+1

jquery के नवीनतम संस्करण का उपयोग करने का प्रयास करें और .done का उपयोग करें, –

उत्तर

10

बदलें रहे हैं इस्तेमाल किया जा सकता अपने successdone के साथ या AJAX फ़ंक्शन के अंदर सफलता का उपयोग करें।

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

ईजी

$(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

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 और error वस्तु द्वारा वापस की विशेषताओं नहीं हैं $.ajax() पर कॉल करें। इसके बजाय, आप कॉल में कॉन्फ़िगरेशन के रूप में उन्हें गुजरना होगा:

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

आप इस डेमो

कुछ अतिरिक्त समारोह जो मदद से आप

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

काम करना चाहिए, इससे पहले, सफलता परिणाम ............ से पहले आपको कुछ अतिरिक्त फ़ंक्शन आग लगने दें। –

संबंधित मुद्दे