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

あなたsuccessdoneajax 関数内で置き換えるか、success を使用してください。

成功コールバック オプションの代替構造である.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 関数内で 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);
           }
      });
 }); 
于 2013-09-03T09:45:17.317 に答える
1

このデモを使用できます

あなたを助けるいくつかの追加機能があります

素敵なデモ

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

successerrorの呼び出しによって返されるオブジェクトの属性ではありません$.ajax()。代わりに、呼び出しで構成としてそれらを渡す必要があります。

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