0

I'm trying to display on the client side the current process on the server.

To do this, I defined string in the session-level, and for each process server processor, it updates it, like this:

sessionStatus = "Loading entities from DB";

or

sessionStatus = "Validates the user information";

I am using ajax and Json like this:

The server side:

[OutputCache(NoStore = true, Location = OutPutCscheLocation.None, Duration = 0)]
public JsonResult GetStatus()
{
        return Json(new {status = sessionStatus}, JsonRequestBehavior.AllowGet)
}

The client side:

setInterval('displayStatus()', 50);

function displayStatus(){
var url = '@(Url.Action("GetStatus"))';
$.ajax({
url: url,
dataType: "json",
async: false,
success: function(result) {
docunent.getElementById('statusText').innerHTML = result.status;
}
});
}

That's how I expect to see every second, which the server process holds.

But the problem is I only see the first action, then the server performs all his actions,

and in the end I see the last action only for a split second.

I mean he's busy all the processes only on the server, and only then faces the client.

Someone can teach me how in the process the server side can continue the operation even on the client, so that I can see in real time what is happening on the server?

Thank you

refael

Refael
  • 6,753
  • 9
  • 35
  • 54
  • do you mean that you want to see the server logs on the client side ? I can't see a way to do that .. unless you add many more ajax calls to fetch the logs from the server. But this will not be in favor of the whole server-client relationship !! – Riju Mahna Jan 22 '13 at 09:44
  • Seems that you have a performance problem. You'll have to see to it that the server manages to respond to your ajax calls besides doing the actual work. If and how this is possible depends a lot on how your server setup is and eventually also on your server hardware. – moritz Jan 22 '13 at 09:51

1 Answers1

0

You could do this utilizing jquerys xhr callback, which lets you create you own XmlHTTPRequest before it is sent.

$.ajax({
  xhr: function()
  {
    var xhr = new XMLHttpRequest();
    xhr.upload.addEventListener("progress", function(e){
      if (e.lengthComputable) {
        console.log("Upload Progress: " + e.loaded/e.total)
      }
    }, false);
    xhr.addEventListener("progress", function(e){
      if (e.lengthComputable) {
        console.log("Download Progress: " + e.loaded/e.total)
      }
    }, false);
    return xhr;
  },
  type: 'GET',
url: "http://upload.wikimedia.org/wikipedia/commons/7/7d/Head_Platon_Glyptothek_Munich_548.jpg",
});
//"Download Progress: 0.017997048457690075"
//"Download Progress: 1"

I hoipe i got the Question right. (And it seems the image is actually not big enough to get a decent progress update, but the idea should be clear

Moritz Roessler
  • 8,542
  • 26
  • 51