Sweet Alert 2, WP Ajax

Necesito usar Sweet alert 2 para borrar registros de una BD la consola dice que esta mal esta parte:

data: { "action": "doDEL", 'delete='+productId }

Отображает следующую ошибку:
Uncaught SyntaxError: Неожиданный токен +

кнопка

echo'<tr><a href="javascript:void(0)"><span class="dashicons dashicons-trash del-button" id="delete_product" data-id="'.$row["persona_id"].'" title="Borrar"></span></a></td></tr>';

JS

<script>
$(document).ready(function(){
//  readProducts(); /* it will load products when document loads */
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
$(document).on('click', '#delete_product', function(e){
var productId = $(this).data('id');
SwalDelete(productId);
e.preventDefault();
});
});
function SwalDelete(productId){
swal({
title: 'Seguro...?',
text: "texto",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Aceptar',
showLoaderOnConfirm: true,
preConfirm: function() {
return new Promise(function(resolve) {
jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: { "action": "doDEL", 'delete='+productId }
})
.done(function(response){
swal('Deleted!', response.message, response.status);
// hacer algo en respuestas
})
.fail(function(){
swal('Oops...', 'Something went wrong with ajax !', 'error');
});
});
},
allowOutsideClick: false
});
}
</script>

PHP wp action

$table = 'table';
add_action( 'wp_ajax_ejemplo', 'doDEL' );

function doDEL() {
global $wpdb;

header('Content-type: application/json; charset=UTF-8');
$response = array();
if ($_POST['delete']) {
$pid = intval($_POST['delete']);
$query = "DELETE FROM {$table} WHERE product_id=:pid";
$stmt = $DBcon->prepare( $query );
$stmt->execute(array(':pid'=>$pid));
if ($stmt) {
$response['status']  = 'success';
$response['message'] = 'Product Deleted Successfully ...';
} else {
$response['status']  = 'error';
$response['message'] = 'Unable to delete product ...';
}
echo json_encode($response);
}
}

Я не знаю много о AJAX, пожалуйста, помогите

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector