📜  从脚本删除请求到 html - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:07.300000             🧑  作者: Mango

代码示例1
// importing elemenets from html
let deleteEl = document.getElementById("delete");
let deleteInputEl = document.getElementById("deleteInput")
let deletResultsEl = document.getElementById("deleteResults")


const display = (data) =>{
  // data = JSON.stringify(data)
  for(let each of data){
    let para = document.createElement('p')
    each = JSON.stringify(each)
    para.innerHTML = each
    getResultel.appendChild(para)
  }
}

const deleteMethod = () =>{
        let url = deleteInputEl.value;
        let options = {
            method: "DELETE"
        };
        fetch(url, options)
            .then(function(response) {
                alert("Data deleted successfully")
            })
            
}

deleteEl.addEventListener("submit", function(event){
    event.preventDefault();
    deleteMethod();
  });