0

我正在尝试在客户端显示服务器上的当前进程。

为此,我在会话级别定义了字符串,并且对于每个进程服务器处理器,它都会更新它,如下所示:

sessionStatus = "Loading entities from DB";

或者

sessionStatus = "Validates the user information";

我正在使用这样的ajax和Json:

服务器端:

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

客户端:

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;
}
});
}

这就是我希望看到的每一秒,这是服务器进程所持有的。

但问题是我只看到第一个动作,然后服务器执行他所有的动作,

最后我看到最后一个动作只在一瞬间。

我的意思是他只忙于服务器上的所有进程,然后才面对客户端。

有人可以教我如何在这个过程中服务器端即使在客户端也可以继续操作,以便我可以实时看到服务器上发生了什么?

谢谢

雷菲尔

4

1 回答 1

0

XmlHTTPRequest您可以使用 jquerys xhr 回调来执行此操作,它可以让您在发送之前创建自己的。

$.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"

我希望我的问题是正确的。(而且看起来图像实际上还不够大,无法获得不错的进度更新,但想法应该很清楚

于 2013-01-22T10:08:39.643 回答