10

在我的 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

4 回答 4

11

在 ajax 函数中替换你success的或使用 success 。done

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

例如

$(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);
           }
      });
 }); 
于 2013-09-03T10:20:18.450 回答
4

尝试在 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);
           }
      });
 }); 
于 2013-09-03T09:45:17.317 回答
1

你可以使用这个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 );                    
        }
        );

}
);
于 2013-09-03T09:50:43.010 回答
0

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

$.ajax({..., success: function(data){}})
于 2013-09-03T09:46:37.740 回答