Skip to content

Instantly share code, notes, and snippets.

@tristansokol
Created July 19, 2017 22:15
Show Gist options
  • Save tristansokol/bafb1e1580c50176b2fa40752b993a60 to your computer and use it in GitHub Desktop.
Save tristansokol/bafb1e1580c50176b2fa40752b993a60 to your computer and use it in GitHub Desktop.
sandbox dashboard blog post pt3 javascript funciton
function deleteCustomer(element){
if(!confirm('Are you sure you want to delete this customer?')){
return false;
}
var location = document.getElementById('location-id').value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText=='deleted'){
alert('deleted');
document.getElementById('table').removeChild(element.parentNode.parentNode)
}else{
alert('something went wrong, check the console');
}
console.log(this.responseText);
}
};
xhttp.open("POST", "delete-customer.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("customerId="+element.getAttribute('customerid'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment