I'm facing an issue with a form that has multiple text boxes containing ids. The problem arises when the user leaves the page, triggering a Python script (delete.py) to delete files on the server. Each file's name includes the corresponding id, so it needs to be passed to the script. Oddly enough, when there is only one id in the form, everything works smoothly and the file gets deleted correctly. However, if there are multiple id fields, none of the files get deleted.
Strangely, when using Firebug to debug the code, the files do get deleted regardless of the number of id fields in the form. I'm puzzled by this behavior and would appreciate any guidance or help to understand what's causing this inconsistency. Below is the onbeforeunload method I have implemented:
function deleteFiles()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
allElements = document.getElementsByName("id");
for (x=0; x < allElements.length; x++)
{
xmlhttp.open("GET", "/cgi-bin/delete.py?id=" + allElements[x].value, true);
xmlhttp.send();
}
}
window.onbeforeunload = deleteFiles;