In Javascript, how to start a server process and control its output until completion?

In my web application, I would like to be able to start the process with certain parameters on the web server and continuously display the output of the process in the text area until it is complete. How can I accomplish this using javascript? I am using jQuery along with ASP.NET MVC 3.

+4
source share
4 answers

I think you need to use some of the new materials. For more details see:

SignalR according to Scott Hanselman

Node.js according to Scott Hanselman

Having said that, all this is new and still under development, I understand. But it seems like this is happening.

+2
source

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 opinion 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); } }); } 
+4
source

you need to send an ajax message (or receive) at regular intervals to the server and get the status of the process.

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

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

+1
source

Source: https://habr.com/ru/post/1369505/


All Articles