[英]How to call function inside ajaxComplete from document ready in jquery?
I want to execute function inside .ajaxComplete()
from document ready. 我想从文档准备好在
.ajaxComplete()
执行函数。
$(function() {
$(document).on('click', '.woof_radio_label', function(e) {
if($(this).siblings('.woof_radio_term').is(':checked')) {
$('.page-secondary-content').removeClass('open');
$('.page-primary-content').removeClass('close');
$(this).siblings('.woof_radio_term_reset').click();
refineUrl();
} else {
$('.page-primary-content').addClass('close');
$('.page-secondary-content, .bottom-content').addClass('open');
}
});
});
$(document).ajaxComplete(function() {
function refineUrl() {
console.log('it works');
}
});
I am prompted with an error below: 出现以下错误提示我:
Uncaught ReferenceError: refineUrl is not defined at HTMLLabelElement.
未捕获的ReferenceError:HTMLLabelElement上未定义finefineUrl。 (scripts-custom.js?ver=4.9.7:15) at HTMLDocument.dispatch (jquery.js?ver=1.12.4:3) at HTMLDocument.r.handle (jquery.js?ver=1.12.4:3)
(HTMLscript.dispatch中的(scripts-custom.js?ver = 4.9.7:15)(HTMLDocument.r.handle(jquery.js?ver = 1.12.4:3))(jquery.js?ver = 1.12.4:3) )
When I click the class woof_radio_label it will trigger an ajax event(Product Filter), I want to call a function on ajaxComplete(). 当我单击woof_radio_label类时 ,它将触发ajax事件(产品过滤器),我想在ajaxComplete()上调用一个函数。
Do you know how to do this? 你知道怎么做吗?
You should declare function refineUrl()
globally and then it can be called from anywhere. 您应该全局声明函数
refineUrl()
,然后可以在任何地方调用它。 From ajaxComplete
and from document.ready
as well. 也来自
ajaxComplete
和document.ready
。
Like: 喜欢:
$(function () {
$(document).on('click', '.woof_radio_label', function (e) {
if ($(this).siblings('.woof_radio_term').is(':checked')) {
$('.page-secondary-content').removeClass('open');
$('.page-primary-content').removeClass('close');
$(this).siblings('.woof_radio_term_reset').click();
refineUrl();
} else {
$('.page-primary-content').addClass('close');
$('.page-secondary-content, .bottom-content').addClass('open');
}
});
});
$(document).ajaxComplete(function () {
//DO another stuff
});
function refineUrl() {
console.log('it works');
}
Declare your refineUrl()
at the top of your script to prevent from such type of errors like, 在脚本顶部声明您的
refineUrl()
,以防止发生此类错误,
function refineUrl() {
console.log('it works');
}
$(function(){
.....
});
$(document).ajaxComplete(function() {
refineUrl();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.