I would like to delete row from front end. This is what i did :
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);
}
);
});
FUNCTIONS.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' );
So in my console i get response :
- 1 for the first row
- 2 for the second row
and so on…
I assume that my code working, but now i can't or i don't know how to execute my delete function… I have read this, but nothing happen.
What am i doing wrong ?
(I hope i'm cristal clear because english is not my language.)
I would like to delete row from front end. This is what i did :
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);
}
);
});
FUNCTIONS.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' );
So in my console i get response :
- 1 for the first row
- 2 for the second row
and so on…
I assume that my code working, but now i can't or i don't know how to execute my delete function… I have read this, but nothing happen.
What am i doing wrong ?
(I hope i'm cristal clear because english is not my language.)
Share Improve this question asked Apr 22, 2019 at 15:17 FlutiFluti 12 bronze badges1 Answer
Reset to default 1You have 1
hardcoded as the row number in mon_action()
.
It should be delete_row( 'field_5c8fa4201b65f', (int) $_POST['param'], $post_id );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745567289a4633471.html
评论列表(0条)