akaballa123
Technical User
Hi There,
Im working on creating an ajax request that will be called through the onunload event in the body tag.
I have set a unique id for my form so that each time the form opens a new id is created. This automatically gets submitted to the database. However, if the user exits the page instaed of submitting it, then I will have to delete the unique id row from the database table.
I have created the code for this, but upon debugging, the unique id does not get delete once i exit the form. I also placed a confirm function in the onunload to see if that works, but the confirm popup does not appear either.
This is the ajax/javascript code that i used to delete the id.
Code:
this is where I call the onunload function:
Code:
lastly this is the php code/page that is called to delete from the table ( i am not sure if i should put this, but i am taking a chance )
Code:
Im working on creating an ajax request that will be called through the onunload event in the body tag.
I have set a unique id for my form so that each time the form opens a new id is created. This automatically gets submitted to the database. However, if the user exits the page instaed of submitting it, then I will have to delete the unique id row from the database table.
I have created the code for this, but upon debugging, the unique id does not get delete once i exit the form. I also placed a confirm function in the onunload to see if that works, but the confirm popup does not appear either.
This is the ajax/javascript code that i used to delete the id.
Code:
Code:
function secIns()
{
<!--
//Browser Support Code
var ajaxRequest; // The variable that makes Ajax possible!
var err = 0;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser is not compatible!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.sessionForm.submitted.value = ajaxRequest.responseText;
}
}
// ajaxRequest.open("GET", "serverTime.php", true);
// ajaxRequest.send(null);
//-->
var secID = document.getElementById('secID').value;
var queryString = "?secID=" + secID;
ajaxRequest.open("GET", "securityIDupdate.php" + queryString, true);
ajaxRequest.send(null);
}
this is where I call the onunload function:
Code:
Code:
<body onunload="if(confirm('Are you sure you want to exit?'){secIns();})">
lastly this is the php code/page that is called to delete from the table ( i am not sure if i should put this, but i am taking a chance )
Code:
Code:
<html>
<body>
<form name="secForm" id="secForm">
<?php
include("mysqlConnection.php");
$secid = $_GET['secID'];
@mysql_query("DELETE FROM trainings WHERE securityId = $secid")or die('Did not delete');
include("mysqlConnClose.php")
?>
</form>
</body>
</html>