RSS ? Recent Blog Posts

Blogs ยป Archive for September 12th, 2006

Eliminating async Javascript callbacks by preprocessing

by Harry Fuecks

The Catch 22 of AJAX is, for the sake of an easy life, most of the time we want to write “synchronous code” but asynchronous is the only way to avoid some rather nasty usability issues. This means rather than being able to write simple code, as we’d like to, such as;

function doClick() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(”GET”,”http://example.com/products”,false);

# Execution blocks here, waiting for the response to complete…
xmlhttp.send(null);
alert(xmlhttp.responseText);
}

…we’re required instead to handle this via callbacks, the simplest example being…

var xmlhttp = new XMLHttpRequest();

function doClick() {
xmlhttp.open(”GET”,”http://example.com/products”,true);

// Set the callback
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}

function handleResponse() {
if ( xmlhttp.readyState == 4 ) {
alert (xmlhttp.responseText);
}
}

…but that’s now introduced a whole load more potential issues. The callback now relies on the global xmlhttp object being available (and globals for any significant size project are generally evil). And what if the user keeps firing that doClick() function? What about async requests that pause for a …

 

Sep 11, 2006 News Wire

by Kevin Yank

 

Catching Session Timeouts before they Bite

by Wyatt Barnett

Using sessions to store user information is a very handy feature of ASP.NET. But it is not without its dark side. One of the principal difficulties is the fact that sessions can die unexpectedly. This can happen for a number of reasons. It could just time out. The server could decide it needs to recycle the application. A user could clear his session cookies. There could be a sunspot. And here is how to catch these events before you corrupt your database.

 

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...