Question: I wish a page to fully load before issuing an ajax call to update database. I can call a javascript function in the body onload event so the page is fully loaded, but I'm not sure how to trigger the Ajax call from there.Is there any better way of achieiving this (Upadating database after page load)?

Answer: 
This is really easy using a JavaScript library, e.g. using jQuery you could write:

```
$(document).ready(function(){
    $.ajax({ url: "database/update.html",
        context: document.body,
        success: function(){
           alert("done");
        }
    });
});

```

Without jQuery, the simplest version might be as follows, but it does not account for browser differences or error handling:

```
<html>
    <body onload="updateDB();">
    </body>
    <script language="javascript">
        function updateDB() {
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "database/update.html", true);
            xhr.send(null);
            /* ignore result */
        }
    </script>
</html>

```

See also:

* [Launching Code on Document Ready](http://docs.jquery.com/How_jQuery_Works#Launching_Code_on_Document_Ready)
* [jQuery ajax](http://api.jquery.com/jQuery.ajax/)
* <http://msdn.microsoft.com/en-us/library/ms535874(VS.85).aspx>
It's even easier to do without a library

```
window.onload = function() {
    // code
};

```