简体   繁体   English

联系表格7 ajax回调不起作用

[英]Contact Form 7 ajax callback not working

Was trying to bind some events to Contact Form 7 for Wordpress, but the event was never called. 试图将某些事件绑定到Wordpress的Contact Form 7,但从未调用该事件。 ref ( Contact Form 7 AJAX Callback ) ref( 联系表格7 AJAX回调

Here's my binding: 这是我的绑定:

$('.wpcf7').on('invalid.wpcf7 spam.wpcf7 mailsent.wpcf7 mailfailed.wpcf7 submit.wpcf7'), function () {
  sb[9].tinyscrollbar_update('relative');
  console.log('invalid');
}

The console.log was never called. 从未调用console.log I'm binding all the events for testing or am I binding it wrong? 我要绑定所有事件以进行测试,还是绑定错误?

This worked for me: 这对我有用:

jQuery(document).on('wpcf7:submit', function () {
        jQuery('#formAlerts').modal();
    });

    jQuery( document ).ajaxComplete(function( event,request, settings ) {

        var alertMessage = $(".wpcf7-response-output").html();
        jQuery(document).find("#formResponse").html(alertMessage);

        function sample() {
            if(jQuery('.wpcf7-form.invalid').length > 0){

        }else{
          jQuery('#formAlerts').modal('hide');
        }
        }

        setTimeout(sample, 2000);

  });

The event isn't bound on the wpcf7 element but rather on the document itself. 该事件不是绑定在wpcf7元素上,而是绑定在文档本身上。

$(document).on('mailsent.wpcf7', function(event) {
    console.log(event)
})

Edit: after looking at the top answer from your link it might be but the above is the way that I've got it and it's working fine for me. 编辑:从您的链接看了最上面的答案后,可能是这样,但是以上是我所掌握的方法,对我来说很好。

Edit 2: it looks like the events in the linked top answer is using different events which may be pushed from the form container and the ones you're trying to use look like the ones that are bound from the document. 编辑2:看起来链接的最高答案中的事件正在使用不同的事件,这些事件可能是从表单容器中推送的,而您尝试使用的事件看起来像是从文档绑定的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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