我想从前端删除行。这就是我所做的:
HTML:
<?php $row = get_row_index(); ?>
<tr data-rownum="\'. $row .\'">
<td>
<span class="deletecontrat iconfont_d" data-toggle="tooltip" data-placement="right" title="Effacer ?">r</span>
</td>
</tr>
AJAX。JS公司
jQuery( document ).on( \'click\', \'.deletecontrat\', function() {
$rownumjs = $(this).parent().parent().data("rownum");
jQuery.post(
ajaxurl,
{
\'action\': \'mon_action\',
\'param\': $rownumjs
}
,
function(response){
console.log(response);
}
);
});
功能。PHP
function add_js_scripts() {
wp_enqueue_script( \'script\', get_template_directory_uri().\'/custom/js/ajax.js\', array(\'jquery\'), \'1.0\', true );
wp_localize_script(\'script\', \'ajaxurl\', admin_url( \'admin-ajax.php\' ) );
}
add_action(\'wp_enqueue_scripts\', \'add_js_scripts\');
function mon_action() {
$param = $_POST[\'param\'];
delete_row("field_5c8fa4201b65f", 1, $post_id);
echo $param;
die();
}
add_action( \'wp_ajax_mon_action\', \'mon_action\' );
add_action( \'wp_ajax_nopriv_mon_action\', \'mon_action\' );
所以在我的控制台里我得到了回应: