Is it possible to use AJAX delete request without using jQuery? My JSON object at localhost:8000 appears like this:
{
"Students":[{"Name":"Kaushal","Roll_No":30,"Percentage":94.5},
{"Name":"Rohit","Roll_No":31,"Percentage":93.5},
{"Name":"Kumar","Roll_No":32,"Percentage":45.5}]}
I am looking for a way to incorporate a delete button that can remove a single record. Any help with the code would be greatly appreciated.
function loadDoc(){
var table2="<tr><th>Name</th><th>Roll_No</th><th>Percentage</th></tr>"
var url2="http://localhost:8000/Students"
var xhttp2=new XMLHttpRequest();
xhttp2.onreadystatechange = function(){
if(xhttp2.readyState === 4 && xhttp2.status === 200){
var jsonArr = JSON.parse(xhttp2.responseText);
for(i in jsonArr){
table2 += "<tr><td>"+jsonArr[i].Name +
"</td><td> "+jsonArr[i].Roll_No+
"</td><td>"+jsonArr[i].Percentage+"</td><tr>"
}
document.getElementById("mytable").innerHTML = table2;
}
}
xhttp2.open('GET',url2,true);
xhttp2.send();
table,th,td{
border:1px solid black;
border-collapse: collapse;
}
<button onclick="loadDoc()" >Get Data</button>
<br>
<br>
<table id="mytable">
</table>