Implementing the message "it's too long" with jQuery

How to implement a gmail-like “it's too long” warning message using the jQuery Ajax API ?

For those who have never seen this message in gmail, it appears when the “signing” process takes too long to complete, and then some solutions are suggested.

I use jQuery Ajax on my website and I want to warn users when the page loads very slowly and then offer some solutions (like a link to refresh the page or to the help page).

+5
source share
3 answers

I would suggest something as simple as this:

function tooLong() {
    // What should we do when something taking too long?  Perhaps show a `<div>` with some instructions?
    $("#this-is-taking-too-long").show();
}

// Then, when you're about to perform an action:
function performSomeAction() {
    var timer = setTimeout(tooLong, 10000);
    $.get('/foo/bar.php', {}, function() {
        // Success!
        clearTimeout(timer);
    });
}
+14
source

Why not just use the jQuery ajax 'timeout' built-in parameter . It is good practice to use it anyway if you have problems with your ajax call. Or, you could invent a wheel;)

edit: and, er, I think you would like to associate this with the error function.

+2
source

The jQuery download plugin I wrote does this as the default option. here is a demo:

http://jquery-values.googlecode.com/svn/other/loading/jquery.loading.htm

http://plugins.jquery.com/project/loading

+2
source

All Articles