Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Let's imagine I have a search page with a SEARCH button.
When I click on it, the java program in the processRequest method execute a query on db, prepare the data and forward the result through the RequestDispatcher. In the java program I can write some instruction to write in a log file the date when it was called (START DATE) and in the finally part when it finished its action (STOP DATE) ...
..
BUT !!!
..
imagine that the rendering on client side by the javascript is badly done and take a hell of time. ... the user will have the feeling of a bad performance, whereas in my log file the START DATE and STOP DATE indicate just 1 seconds of treatement.
..
SO
....
Is there a way so that at the end of the rendering by the javascript, I call again in a silent mode the server so that in its log file it just add one more date telling me when the user is able to work (READY DATE)
.
If I want to measure the real end user performance of my application, I will be able now to compare the READY DATE versus the STOP and START dates and I can also have an idea of how long it took between the time the server finished it works and the network return + rendering. .... so I can also somehow detect potential network abnormal latency ....

What I have tried:

Nothing yet ... the problem is that the page is rendered so most probably I cannot at that stage call again the server even silently otherwise I create a new post request ....
Posted
Updated 24-Jan-17 2:53am
v2

You are going to have to stage an asynchronous call in the callback using either a jquery .ajax call or an XMLHTTPRequest object. Your function should look something like this:

JavaScript
function someFunction(args, callback) {

dosomething here;
callback();


}

function callback() {

$.ajax();


You will have to look up the ajax syntax for what you want to do, it is reasonably simple to fire a controller call from here. Since a log entry is truly asynchronous, it is pretty trivial to just fire a call to a link and forget without needing an additional callback from your ajax function.
 
Share this answer
 
You can use callback.What call does is,on complete of any function,it is called.You can also pass parameters in callback also.
function getDBData(callback) {
    $.ajax({
        type: "POST",
        url: "your url",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
           //your code here to retrieve data from db
        },
        complete:function () {
            if(callback) {callback();}
        }
        error: function (jqXHR, exception) {
          //your error message goes here
        }
    });
}

Hope,this works!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900