admin管理员组文章数量:1406060
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
4 Answers
Reset to default 4You 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
本文标签:
版权声明:本文标题:jquery - In Javascript, how to start a server-side process and monitor its output until completion? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744965467a2634920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论