I have an account database on my Mac that uses HTML, Javascript & PHP to delete an account after I click the delete button. It works every time in FireFox and fails every time in Safari (fail meaning the delete request is completely ignored).
Essentially, this is what my code is doing…
- Button
onclickinside a Form calls a js funcverifyDelete()asking me to verify my choice to delete - Next, the
onsubmitfrom same form calls a js funcdelAccount() - Finally,
delAccount()usesXMLHttpRequestto call a php page to delete the
account
I got the idea of using the XMLHttpRequest from looking at AJAX. I didn’t need all the ReadyState, Response, etc. that AJAX uses so I just used what I needed. Is it ‘legal’ to do what I did inside the delAccount() function? Maybe that’s why Safari is failing?
Any help is appreciated, here’s my code…
FILE – View.php
<?php
// some code
?>
<form method="get" onsubmit="return delAccount('<?php echo $acctNum; ?>')">
<input type="hidden" name="acctName" value="Blah” />
<button onclick="return verifyDelete()" >Delete</button>
</form>
<?php
// some code
?>
FILE – common.js
function verifyDelete() {
var r=confirm("Are you sure you want to Delete this?\r\n\n" +
"A) 'Cancel' delete request\r\n" +
"B) 'OK', delete\r\n");
if (r == false) {
return false;
}
else {
return true;
}
}
function delAccount (acctNum) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlDelete = new XMLHttpRequest();
}
xmlDelete.open("GET", "delAcct.php?q=" + acctNum, true);
xmlDelete.send(null);
return false;
}
FILE – delAcct.php
<?php
// code to delete account
?>
I overlooked something. I just needed to swap
truewithfalsefor theXMLHttpRequest…I get that it makes the event synchronous, but i don’t really know why this work and the other didn’t.