简体   繁体   中英

Failing to call a function after AJAX completes

I have a function named ajaxCall which makes an AJAX call. I have another function called filterItem . On button click of filter I want the ajaxCall function to fire so that all items can be retrieved then the filterItem function should fire and filter items. However this function is not triggered.

$(document).on('click', '.items', function() {
    ajaxCall().promise().done(function() {
        alert();
        console.log("trigger");
        filterItem();
    });
});

In Ajax call there is an async Property make it false and it should work. No need to use .promise()

$.Ajax({
type:  "Post",
url: "Your URL",
async: false,
success : function(){
alert("ajax Complete");
}
});

You can also call your dependent function in Success block if it is possible in your scenario.

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