加载AJAX后在Contact Form 7表单上启用AJAX [英] Enabling AJAX on Contact Form 7 Form after AJAX Load

查看:151
本文介绍了加载AJAX后在Contact Form 7表单上启用AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索,但这只会返回有关如何AJAX加载页面/表单的结果. 我正在做的是通过AJAX加载表单(联系表单7),我想知道如何在该表单上重新启用AJAX提交. CF7有可能吗?

I've tried searching but this only returns results on how to AJAX load a page/form. What I am doing is loading a form via AJAX (Contact Form 7) and I would like to know how to re-enable AJAX submission on that form. Is this a possibility with CF7?

推荐答案

联系表7调用一个init函数,该函数在页面加载时执行.如果您的表单是使用AJAX加载的,则应确保在加载表单后调用该函数.

Contact Form 7 calls an init function, which executes on page load. If your form is loading using AJAX, you should make sure that the function gets called after your form is loaded.

查看:

plugins/contact-form-7/includes/js/scripts.js

用于定义功能wpcf7InitForm.

修改: 每次调用此函数都会插入一个新的加载徽标.不幸的是,我找不到比使用jQuery从DOM中删除重复加载器更好的解决方案:

Calling this function inserts a new loading logo each time. Unfortunately, I couldn't find a better solution than deleting the duplicate loader from DOM using jQuery:

function initContactForm() {
    jQuery('div.wpcf7 > form').wpcf7InitForm();
    jQuery('form.wpcf7-form')
        .each(function() {
            $j(this).find('img.ajax-loader').last().remove();
        });
}

这篇关于加载AJAX后在Contact Form 7表单上启用AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆