[英]Failing to call a function after AJAX completes
I have a function named ajaxCall
which makes an AJAX call. 我有一个名为
ajaxCall
的函数,它调用AJAX。 I have another function called filterItem
. 我有另一个名为
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. 在按钮上单击过滤器我想要
ajaxCall
函数,以便可以检索所有项目,然后filterItem
函数应该触发和过滤项目。 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. 在Ajax调用中有一个
async
属性使其成为false
,它应该工作。 No need to use .promise()
无需使用
.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. 如果在您的方案中可以,您还可以在Success块中调用依赖函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.