Javascript 使用js数组push()向我的表添加删除链接
我想在我的表格中加入一个删除按钮的链接。这将根据ID从我的数据库中-onclick-delete 我在堆栈溢出中进行了搜索,但没有成功。在正确的方向上的一点将是伟大的(链接,代码建议等…) HTML:Javascript 使用js数组push()向我的表添加删除链接,javascript,php,mysql,slim,database-table,Javascript,Php,Mysql,Slim,Database Table,我想在我的表格中加入一个删除按钮的链接。这将根据ID从我的数据库中-onclick-delete 我在堆栈溢出中进行了搜索,但没有成功。在正确的方向上的一点将是伟大的(链接,代码建议等…) HTML: <h5 class="tabletext"><a href="#">View Markers</a></h5> <form action="" method="post"> <table class="t
<h5 class="tabletext"><a href="#">View Markers</a></h5>
<form action="" method="post">
<table class="table table-bordered">
<thead>
<tr>
<th data-field="id">ID</th>
<th data-field="type">Type</th>
<th data-field="area">Area</th>
<th data-field="area">Weight in lbs</th>
<th data-field="area">Length in cm</th>
<th data-field="area">Latitude</th>
<th data-field="area">Longitude</th>
<th data-field="area">DELETE</th>
</tr>
</thead>
</table>
</form>
你可以在delete按钮上附加一个事件,并通过ajax发送到api进行删除。我不知道,你会有任何教程链接吗@Agambanga如果您有任何问题,这应该可以帮助您让我知道
$.ajax({
type: 'GET',
dataType: "json",
url: "rest/rest/api.php/markerss",
success: showMarkerTable,
error: showError
});
function showMarkerTable(responseData) {
var items = [];
$.each(responseData.MARKERS, function(key, val){
items.push("<tr>");
items.push("<td id=''"+key+"''>"+val.id+"</td>");
items.push("<td id=''"+key+"''>"+val.area+"</td>");
items.push("<td id=''"+key+"''>"+val.type+"</td>");
items.push("<td id=''"+key+"''>"+val.weight+"</td>");
items.push("<td id=''"+key+"''>"+val.length+"</td>");
items.push("<td id=''"+key+"''>"+val.lat+"</td>");
items.push("<td id=''"+key+"''>"+val.lng+"</td>");
//The delete button here
items.push("<td id=''"+key+"''>"+val.delete+"</td>");
items.push("</tr>");
});
$("<tbody/>", {html: items.join("")}).appendTo("table");
}
function showError(){
alert("Sorry, there was a problem!");
}
function getTable() {
$sql="select * FROM markers ORDER BY id";
try{
$db = getConnection();
$stmt = $db->query($sql);
$markers = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
responseJson('{"MARKERS":'.json_encode($markers).'}',200);
}
catch(PDOException $e){
responseJson('{"error":{"text":'.$e->getMessage().'}}',500);
}
}