1
我試圖在我的wordpress網站上使用smoothstate.js實現聯繫表格7。當使用該頁面的頁面直接加載時,聯繫表單可以很好地工作。但是,如果通過AJAX加載頁面,則會顯示錯誤「wpcf7.initForm不是函數」。通過AJAX(smoothstate.js)加載頁面時,聯繫表格7引發'wpcf7.initForm不是函數'錯誤
我不是AJAX的天才,但我的想法是在AJAX onAfter函數中重新初始化。我通過使用wpcf7InitForm()來試試這個;但仍然沒有運氣。
任何有關這個主題的幫助將不勝感激!
這是我目前的AJAX代碼:
//SmoothState Page Transitions
$(function(){
'use strict';
var $page = $('#main'),
options = {
debug: true,
prefetch: true,
onStart: {
duration: 800, // Duration of our animation
render: function ($container) {
// Add your CSS animation reversing class
$container.addClass('is-exiting');
// Restart your animation
smoothState.restartCSSAnimations();
}
},
onReady: {
duration: 0,
render: function($container, $newContent) {
// Remove your CSS animation reversing class
$container.addClass('is-loaded');
setTimeout(function(){
$container.addClass('unload');
}, 600);
setTimeout(function(){
$container.removeClass('is-loaded unload');
}, 900);
// Inject the new content
$container.html($newContent);
}
},
onAfter: function($container) {
$container.removeClass('is-exiting');
$('div.wpcf7 > form').wpcf7InitForm();
$(window).data('plugin_stellar').refresh();
}
},
smoothState = $("#main").smoothState(options).data("smoothState");
});