AJAX - The Complete Reference

(avery) #1

520 Part III: Advanced Topics


$delay = rand(1,20);
sleep($delay);
print 'Hello World at '. date("h:i:s A");
?>

The network trace here shows the long poll pattern in action:

NNOT EOTE Close- and timer-based re-establishment of connections is not limited to an XHR
communication; iframes or other transports can use a similar mechanism.

The Long Slow Load

For many, the long slow load pattern or endless iframe is what they think of when the term
Comet is used. We demonstrate here making an iframe connection to a server-side program,
indicating where we want the response data to be placed in this case a <div> named
“hellodiv.”

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Free download pdf