yad4u Are there progress update events in jQuery ajax?
صفحه اصلي

Are there progress update events in jQuery ajax?

i have long running task that gets called using jquery ajax. i am using the block ui plugin to show "loading". is there anyway i can send progress messages back to the client to show progress and have that updated on the block ui plugin message.

So it will show this (as the server does its work) . .

"Loading first source . . . "
"Loading second source . . . "
"Loading third source . . . "
"Parsing Results . . . "

Thoughts on writing a “flexible” API?


How to get current route information in OnActionExecuting
From what I've seen for the case of uploading stuff - people create a separate gateway and query it for progress info as it's only avaliable on the server side. Need advice on multitab form in ASP.NET MVCBut I think it's not the best thing in Your case.. I set a property in my custom controller wrapper in OnActionExecuting, how to pass to Site.Master? If You want to load stuff with progress information or allow server to pop info on progress while generating output then http streaming is what You want. Using DataAnnotations 4.0It's covered nicely here. Is my System Administrator crazy :-) Does ASP.NET MVC break when the server's Physical Path is in UNC format?Basically it's a single http request, to which the server responds in chunks for a minute or so (therefore sending stuff when it wants) and then a new connection is opened.. How does the App_LocalResources work with MVC? This was quite a discovery for me ;). Excluding an action from authorization in ASP.NET MVC 2 [edit]. Currently there are lots of better techniques avaliable, and all of them are wrapped up in Socket.IO - Websockets with fallbacks to another techniques including http streaming. Socket.IO is a module for nodeJS, although there are another and similar implementations. I have already exchanged any packets with JAVA Socket.IO implementation from https://github.com/Atmosphere/atmosphere.


One way is to use HTTP Handlers and AJAX with jQuery.. 1. Initiate Server side request.
$("#btnCreateInvoice").click(function() {                     $.ajax({ type: "POST",  url: "YourHttpHandler.ashx",        contentType: "text/html; charset=utf-8",        dataType: "html",          success: function(data) { start the block UI }        });     }); 
2. Polling. What next you need to did is to poll the server at 't' interval and receive the status. For this i need to call a function at 't' interval this would initiate an AJAX call to a HTTPHandler to receive the status..
$(function() {   setInterval(updateStatus, 't'); });  function updateStatus() {   $.ajax({ type: "POST",  url: "GetStatusHandler.ashx",        contentType: "text/html; charset=utf-8",        dataType: "html",          success: function(data) { process 'data' here and update the block UI message box }        }); } 
In your case here, the GetStatusHandler.ashx must return the complete innerHtml for status. For eg on the first call it will return 'Loading First source...', then it might return: Loding First source... Loading Second source... and so on..


I only recently became aware of a project this does ajax "push". You might want to check it out:. http://www.ape-project.org/. As far as I know there are a few another projects out there doing similar things, this is the truest to: "send progress messages back to the client" where the another quick fix requires a request to poll for progress (still a very legitimate and good solution)..


I would have each AJAX request return a JSON response containing a message, the data, and the next URL to request: {message: "Loading second resource...", data: ..., next_url: "/next_part"}. Before your first AJAX request, set the BlockUI message to "Loading...". When you receive the response, set the BlockUI message to the message you receive back from your AJAX call. Then make the next AJAX call to the value of "next_url", and so on, looping until you've completed all of the tasks.. If you're loading one large data set, although in pieces, you may want to did any thing like a progressive loading design pattern, although also set a progress message as you receive each response..


What you are endeavor to did is any thing similar to Comet. Traditional ("non-comet") webservers are not designed for this kind of transaction model and is therefore not a desired solution.. My suggestion is to break up the processing in one client request per data source:.
function loadData() {    // Each call passes callback(id) as a success handler    fireAsynchronousRequest("source1");    fireAsynchronousRequest("source2");    fireAsynchronousRequest("source3"); }  function callback(var source) {    if (source == "source1") {        updateStatus("Source 1 loaded");    }    else if (source == "source2") {        updateStatus("Source 2 loaded");    } } 
This is an case of an asynchronous solution. You must implement state handling in callback() if you need it to be synchronous..


Well I had a similar position and I solve it with ananother approach. It is a VERY UGLY job around, I know this so please did not start stating how bad it is, cause I know it, although it was ok for what I need it.. I'm putting the progress in a file, on the server side. For example, I have process.php called which needs to did a lot of job and it takes a while till it complete, so the user is receive ting nervous and he close the browser (not too good). So process.php is saving any output to a file on the server. On the page which called the process.php I have a small div, span, or whatever where I want to display the progress, although I suggest div. Each X millisecond, or seconds, I load ananother script from the server in the div, let's say display_info.php Now display_info.php is reading the file which was outputed by process.php and the content is diplayed in the div.. You have to be careful this the output from process.php has to be unique for each occasion, otherwise you will mess up the info output to the browsers.. Emil.

56 out of 100 based on 41 user ratings 716 reviews