jquery - In Javascript, how to start a server-side process and monitor its output until completion? - Stack Overflow

In my web application I'd like to be able to start a process with certain parameters on the web se

In my web application I'd like to be able to start a process with certain parameters on the web server, and continuously display output from the process in a text area until it pletes. How can I acplish this with Javascript? I'm using jQuery along with ASP.NET MVC 3.

In my web application I'd like to be able to start a process with certain parameters on the web server, and continuously display output from the process in a text area until it pletes. How can I acplish this with Javascript? I'm using jQuery along with ASP.NET MVC 3.

Share Improve this question asked Aug 29, 2011 at 15:04 aknuds1aknuds1 68.2k69 gold badges206 silver badges320 bronze badges 4
  • You can't acplish this with "javascript" it's done with HTTP. – Raynos Commented Aug 29, 2011 at 15:07
  • @Raynos Do you suggest I perform dynamic updates in the client view with HTTP? :P – aknuds1 Commented Aug 29, 2011 at 16:30
  • you make HTTP requests to a server to start the process, then make further HTTP requests to extract data. You can render it however you want. – Raynos Commented Aug 29, 2011 at 16:40
  • @Raynos It was a rhetorical question. – aknuds1 Commented Aug 29, 2011 at 17:01
Add a ment  | 

4 Answers 4

Reset to default 4

You can do this with 2 action methods and a javascript timer

[HttpPost]
public JsonResult StartProcess()
{
    StartTheMachine();
    return new JsonResult() { Data = "Started" };
}

[HttpGet]
public JsonResult GetProcessUpdate()
{
    return new JsonResult() 
    {
        Data = GetUpdate(), 
        JsonRequestBehavior = JsonRequestBehavior.AllowGet 
    };
}

and in your view something like this:

$.post("<%=Url.Action("StartProcess") %>", function(data) {
    // do something with data "Started" and start timer
    setTimeout(GetUpdate, 5000);
});

function GetUpdate()
{
    $.get("<%=Url.Action("GetUpdate") %>", function(data) {
        if (data.Complete) // or some way to tell it has finished
        {
            // do something with other data returned
        }
        else
        {
            // call again if not finished
            setTimeout(GetUpdate, 5000);
        }
    });
}

I think you need to use some of the new stuff ing out. For details see:

SignalR according to Scott Hanselman

Node.js according to Scott Hanselman

Having said that, it is all new, and still under development I understand. But it looks like the way this kind of development is going.

you need to send a ajax post(or get) in regular time intervals to server side and get the process status.

$.get("controler/ActionToReturnStatusView", null,
   function(data){
     alert("status " + data);
   });

can use et programming. can try web workers supported in HTML 5

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744965467a4603652.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信