获取TypeError:$ .ajax(...)。done不是函数[Ajax,Jquery]

时间:2013-09-03 09:37:45

标签: javascript ajax jquery

在我的Jquery中,我正在使用Ajax并获得低于错误的消息。

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

4 个答案:

答案 0 :(得分:11)

success替换为done或在ajax函数内使用成功。

  

成功回调选项的替代构造,.done()   方法替换已弃用的jqXHR.success()方法。

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

答案 1 :(得分:3)

尝试在ajax函数中使用success函数,

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

答案 2 :(得分: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 );                    
        }
        );

}
);

答案 3 :(得分:0)

successerror不是调用$.ajax()返回的对象的属性。相反,你必须在调用中将它们作为配置传递:

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