Handling AJAX Timeouts

Development by matt on May 24th, 2007 No Comments

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;
}
No Responses to “Handling AJAX Timeouts”

Leave a Reply

You must be logged in to post a comment.