I have a form with a variable number of text boxes that contain an id. When the user exits the page, files on the server are deleted by a python script (delete.py). The filename of the files to delete contains the id so the id has to be passed to the python script. If my form has a single id, everything works perfectly and the file on the server is deleted. If my form has multiple id fields, no files get deleted. If I use firebug to step through the code, the files gets deleted regardless of the number of id fields. I don’t understand what is going on. Any help would be greatly appreciated. My onbeforeunload method is below.
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;
Sounds like the request’s are being sent too fast. Try adding
xmlhttp.async = false;
Let me know your findings