我使用本地存储json文件来保存表单数据。但我想出于某种目的制作删除功能。我使用一个按钮来使用id号更新我的json对象。 这是我用于存储数据的json代码。
{
"id":"6",
"firstname":"dmk",
"lastname":"stc",
"age":"32",
"is_active":"true"
}
我想在表单中删除按钮单击时将is_active设为false。如何获取模型或警告并删除它。
<a type='submit'
class='btn btn-danger btn-sm'
role='button' id='btnDelete'
style='margin-left: 10px;'>
Delete
</a>
这是我使用json文件
检索数据的javascript代码var output = document.getElementById('output');
var ajaxhttp = new XMLHttpRequest();
var url = "form.json";
var xhttp = new XMLHttpRequest();
var details = '';
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = JSON.parse(xhttp.responseText);
var people = response.people;
var output = '';
output += "<table class='table table-bordered'>";
output += "<tr><th scope='col'>id</th><th>First Name</th><th>Last Name</th><th>Age</th><th>Action</th></tr>";
for(x in response){
output += "<tr><td>" + response[x].id + "</td><td>" + response[x].firstname + "</td><td>"+response[x].lastname+"</td><td>"+response[x].age+"</td><td><a href='edit.php?id="+response[x].id+"&firstname="+response[x].firstname+"&lastname="+response[x].lastname+"&age="+response[x].age+"' class='btn btn-primary btn-sm active' role='button' aria-pressed='true'>Edit</a><a href='index.php?id="+response[x].id+"' class='btn btn-danger btn-sm' role='button' id='btnDelete' data-toggle='modal' data-target='#exampleModal' style='margin-left: 10px;'>Delete</a></td></tr>";
}
output += "</table> ";
// Typical action to be performed when the document is ready:
document.getElementById("output").innerHTML = output;
}
};
xhttp.open("GET", url, true);
xhttp.send();