tags:

views:

30

answers:

2

I am absolutely terrible at logging my hours.

So my idea is to have a browser shortcut that i open when i am starting work.

Then when i am finished close it.

This will then to an ajax request to a php script that will update my hours for me.

To do this.

Can i do an ajax request in $(window).unload()? or will the browser close before this completes? and, will the php script on the other end run?

+1  A: 

Unless you make a synchronous AJAX request, the browser will not wait for the request to finish before closing.

Rowno
+3  A: 

You can run an synchronous AJAX request (async: false in $.ajax()) in window.onbeforeunload, but an asynchronous one (the default) will most likely be cancelled before it completes. Note that this isn't the same as the unload event, which is strictly for variable cleanup (though beforeunload is arguably for the same purpose).

I tend to recommend against doing this, as it delays the user's experience waiting on your AJAX request to complete, when they just want the next page.

Nick Craver
But for a situation as i have described in my question would you recommend this, or would you say, log automatically every 10 minutes?
Hailwood
@Hailwood - I'd say that's a good alternative, whatever fidelity you need with the minutes would work.
Nick Craver