admin管理员组文章数量:1026989
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 );
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 );
本文标签: ajaxDelete ACF repeater field row on Front End
版权声明:本文标题:ajax - Delete ACF repeater field row on Front End 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745567286a2156527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论