Hi there,

I've set up a page that records the times (in a database) users login to it (start time), and I wanted to be able to determine the times they left the page (leave time), so I used the javascript onUnload function along with an Ajax request. This is my script:

window.onunload = function () {
new Ajax.Request('end.php');
}

Where end.php is a php file with the code that submits the time info to the database.

This works perfectly in Firefox and IE7. The problem I have is that the AJAX doesn't seem to be working in Safari or Chrome, and the onUnload() function doesn't work in Opera (I'm not too worried about this one - mainly want Safari to work). I'm not sure of how this works in IE6, I haven't been able to test it yet.

I need this to work in as many browsers as possible because it's important that leave times be recorded for this page.

Is there something wrong with the code I've written?
Is there another way to achieve what I am trying to do?

Thanks in advance!

    Your using some kind of framework. That is likely out of date. You need to show us the code that actually handles the "Ajax.Request".

      Thanks for the quick reply!

      I'm using prototype-1.6.0.3.js should I be using a different framework? This is the latest version of prototype.

      On a side note: I don't understand how to use Ajax, or how it really works...I just know I am going to have to use it in order to use the PHP code when the user leaves the page (the onunload() call).

        I have heard of it, but have never used it.

        I am guessing there must be something they did that causes the browser incompatibility. Becasue the "XMLHttpRequest()" function is compatible on FireFox, Safari and Opera. So if it works in FireFox but not Safari they added some code that Safari doesn't like.

        Here is a link to the W3C website on AJAX - Sending a Request to the Server maybe it a help you see something.

        Other wise try posting the functions that handles the "XMLHttpRequest()".

          Write a Reply...