Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

how to send update client browser at regualr interval using asp.net and jquery

I have a web page and this contains a button, if user clicks on this button then I have to run a process a long time taking task.

now i am planning to use using asyn handler or asyn page to do this task.
but what i need to send text string at regular interval to the client about the process say after every 5 sec I need to send a update text.

is it possible to do so?
0
ziorrinfotech
Asked:
ziorrinfotech
1 Solution
 
alien109Commented:
using setInterval, you can continuously execute a function. it's hard to provide sample code, without knowing more, but essentially you could do something like this -

function pollServer() {
    $.get(...., function(response) {
        // response from server should contain update text or
        // a flag to indicate if we should stop polling...

        // if we send back a flag to signal the task is complete...
        if(response... == "complete")
        {
                //stop polling the server
                clearInterval(intervalId);
        }
    })
}

var intervalId = setInterval(pollServer, 5000);

create a function that polls the server, then start calling that function on an interval, storing a reference to the interval's id so that we can stop it later.

in side of the polling function we use jquery to call the server and get a response. based on what is returned (and how it is returned) we can then determine if we should stop executing the polling function or display a message...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now