简体   繁体   中英

jQuery ajax success function inside success function?

I am trying to call an ajax function inside the success function of a function. This is my code:

success: function () {
    jQuery.ajax({
        type: "POST",
        url: "script.php?subtype=3",
        data: "page=1",
        beforeSend: function () {
            jQuery(".data").animate({opacity: 0.2}, 150);
            jQuery(".outer-data").css({'background': 'url("ajax-loader.gif") no-repeat scroll 50% 50%'});
        },
        success: function (msg) {
            jQuery("#container_cat").ajaxComplete(function (event, request, settings) {
                jQuery(".outer-data").css({'background': 'none'});
                jQuery("#container_cat").html(msg);
            });
        }
        // ...
    });
}

Even though I get the response in Firebug console from

jQuery("#container_cat").html(msg);

I don't get any output in the document.

What am I missing here?

success: function () {
    jQuery.ajax({
        type: "POST",
        url: "script.php?subtype=3",
        data: "page=1",
        beforeSend: function () {
            jQuery(".data").animate({opacity: 0.2}, 150);
            jQuery(".outer-data").css({'background': 'url("ajax-loader.gif") no-repeat scroll 50% 50%'});
        },
        success: function (msg) {
            jQuery(".outer-data").css({'background': 'none'});
            jQuery("#container_cat").html(msg);
        }
        // ...
    });
}

Seems like the problem is that you are calling the ajaxComplete() function inside the success function. You dont need to use ajaxComplete inside success function as success function will only be executed when the ajax request is completed and succeeded. So theres no sense of using ajaxComplete inside it. For reference : ajaxComplete docs You can use ajaxComplete before success function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM