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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744965467a4603652.html
评论列表(0条)