【发布时间】:2016-03-05 11:46:37
【问题描述】:
大家好,我在我的 PHP 文件中使用 ajax 来删除表中的条目,这是我的代码:
<?php foreach (get_all_categories() as $r) { ?>
<td>
<?php
echo '<button type="button" class="btn btn-primary delete delete-action"><i class="fa fa-trash-o fa-lg"></i> Delete</a></button>
<input type="hidden" value="'. $r['category_id'] .'" name="delete[]">';
?>
</td>
<?php } ?>
//AJAX CALL
var id;
$('button.delete-category').click(function(e) {
id = $(this).parent()[0].childNodes[3].value;
swal({
title: "Are you sure?",
text: " You will not be able to undo this action !",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false,
html: false
}, function(){
$.post( "delete_category.php", { deletecategoryfunction: id}, function( data ) {
location.reload();
});
});
});
但是我的问题是,如果我有一个编辑按钮,我将如何使用 AJAX 进行编辑,过去几天我一直坚持这个问题,这就是在这里提出这个问题的原因。
$r 基本上会拉出我称为类别的表中所有项目的列表,其中包含(类别名称、描述和可用性。)所以当我这样做时,无论如何我都可以这样做,以便我可以更改或修改类别表的类别名称、描述和可用性。
【问题讨论】:
标签: javascript php ajax foreach