Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

event onUnload

22 views
Skip to first unread message

Asier Ramos

unread,
Mar 30, 2009, 5:15:27 AM3/30/09
to dev-...@lists.mozilla.org
I have a problem with Javascript event OnUnload. I want to update a record
in a database as many times as onunload event is called. I have that code
for do this:

*ajax.js*

function MyAjax() {
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

return xmlhttp;
}

function ClearHTML(sHTML) {
sHTML = sHTML.replace(/<[^>]*>/gi, "");
sHTML = sHTML.replace( /\n/gi, "") ;
sHTML = sHTML.replace(/&nbsp;/gi, "");

return sHTML;
}

*borrar_temp.php*

<?
session_start();
require_once("inc/functions.inc.php");
require_once("inc/sections.inc.php");
require_once("inc/conection.inc.php");

$Hoy=date("Y-m-d")." ".date("H:m:s");
$sql="update sesiones set session_destroy='".$Hoy."' WHERE
session_id='".$_SESSION['IdSession']"'";
mysql_query($sql);
session_destroy();


?>

*index.php*

<html>

<head><script language="javascript" src="js/ajax.js"
type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
//Función para guardar tu informacion en bd utilizando ajax.
function cargarContenido()
{
var miAjaxObj = MyAjax();
miAjaxObj.open("GET","borrar_temp.php",true);
miAjaxObj.send(null);
alert("ejecutado");
}

</script></head>

<body onunload="cargarContenido();">
</body>
</html>


The result of that is that the Javascript makes ok, but php code no...

Thanks!!

0 new messages