Handling AJAX Timeouts

Comments (0)

AJAX applications can be a great way to deliver rich functionality through the portal, but timeout issues can be frustrating to debug. In particular, clicks in an AJAX application cause HTML to be loaded through the gateway, but if the gateway times out, the portal will return its own HTML in the asynchronous response:

AJAX Timeout

AJAX calls are usually implemented by creating a request and asynchronously writing the response out to the tag. An easy way to prevent the portal error from appearing inside the portlet is to check the returned HTML before writing it out to the div tag; searching for the error string allows you to write out your own error rather than using the portal's.

    var htmlFromAJAXCall = response.getResponse();
    if (htmlFromAJAXCall.substring("Error - ") == -1) {
        document.getElementById("responseDivTag").innerHTML = "A timeout error has occurred; trying again"; 
        // repeat the AJAX request again
    }
    else {
        document.getElementById("responseDivTag").innerHTML = htmlFromAJAXCall;
    }

Leave a comment

Recent Entries

AJAX Refresher
It's been a while since we touched on AJAX, but a question came up recently about it an I thought…
The Stack Trace Strikes Back
Howdy all. Welcome to part two of three of what was originally conceived as a one part series. It's entirely…
Cool Tools Part XVI: My Love Affair With JAD
Hi, my name is Brian.  I like sunsets, long walks on the beach, puppies, and de-compiling Java code.  If you…