您应该以这种方式来处理ajax请求。这是recommended way to make a ajax call in WordPress.
my_function.js更新您的jquery
使用此代码。
jQuery(document).ready(function($) {
$(\'#submit_payment\').click(function(e){
e.preventDefault();
var str = $("form[name=season-form]").serialize();
//alert(str);
$.ajax({
type: "POST",
url: \'//www.example.com/wp-admin/admin-ajax.php\',
data: str + \'&action=confirmRequest\'
}).done(function(data){
$("#result").html(data);
});
});
});
ajax_request_handling将此粘贴到
functions.php
你的主题。
function _myConfirmHandler()
{
if(isset($_POST[\'vehicle_no\']))
{
$vehicle_no = $_POST[\'vehicle_no\'];
$email = $_POST[\'email\'];
echo "Your Data: <br>$vehicle_no <br>$email<p />";
}
echo do_shortcode(\'[cfdb-table form="season parking form_copy"]\');
echo do_shortcode(\'[contact-form-7 id="23" title="Contact form 1"]\');
exit;
}
add_action(\'wp_ajax_confirmRequest\', \'_myConfirmHandler\');
add_action(\'wp_ajax_nopriv_confirmRequest\', \'_myConfirmHandler\');
For more information refer to the link.