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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18588861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:00:39  来源:igfitidea点击:

Getting TypeError: $.ajax(...).done is not a function [Ajax, Jquery ]

javascriptajaxjquery

提问by Shailendra Kumar

In my Jquery, i am using Ajax and getting below error msg.

在我的 Jquery 中,我使用 Ajax 并收到以下错误消息。

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

I tired using success instead of done. but still getting same msg.

我厌倦了使用成功而不是完成。但仍然收到相同的消息。

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

sample piece of code is mentioned below:

下面提到了示例代码:

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

回答by Konsole

Replace your successwith doneor use success inside ajax function.

在 ajax 函数中替换您successdone或使用成功。

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

成功回调选项的替代构造,.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);
           }
      });
 }); 

回答by Mujtaba Haider

try using success function inside ajax function ,

尝试在 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);
           }
      });
 }); 

回答by Shakti Patel

You can used this Demo

你可以使用这个Demo

There are some extra function which help you

有一些额外的功能可以帮助你

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

}
);

回答by Aaron Digulla

successand erroraren't attributes of the object returned by the call to $.ajax(). Instead, you must pass them as configs in the call:

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

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