Datasheet
this.callbackList = {
success: this.handleListSuccess,
failure: this.handleListFailure,
scope: this
};
Basically, this means that if the response is OK, handleListSuccess will be called and if not,
handleListFailure will be called. In both cases, the context with which these methods are called is the
context of this object (this being the controller). When
YAHOO.util.Connect.asyncRequest is called,
the YUI sends a request to the server and this request is what was logged as the last line of your web
server log snippet earlier:
12:37:00 200 GET /buzzwatch/watch.php (application/xml)
The request sent by the library is similar to the one that you have already seen, and there is nothing to
tell you that it was sent by the YUI:
GET /buzzwatch/watch.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060608
Ubuntu/dapper-security Epiphany/2.14 Firefox/1.5.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;
q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Serving content coming from SQL databases as XML is a very frequent task for Web 2.0 applications.
The PHP script that does that for BuzzWatch has been developed to show that this is simpler than you
may think if you want to do it by hand, but there are also a number of generic tools that can do that for
you. This subject is covered in Chapter 12.
The HTML document was a static file, and now we are accessing a dynamic PHP script on the server.
This PHP script queries the SQLite database, retrieves a list of available watches, and sends this list as
XML. This PHP script,
watch.php, can do more than that: it can also save a new watch and display a
single one. Its main part is:
header(“Cache-Control: max-age=60”);
header(“Content-type: application/xml”);
echo ‘<?xml version=”1.0” encoding=”utf-8”?>’;
if (strlen($HTTP_RAW_POST_DATA)>0) {
write();
} else if ($_GET[‘name’]) {
readOne();
} else {
listAll();
}
The first instructions are to set HTTP headers like those you saw in the previous traces. The first one
sets the time the document should be considered as fresh. Here, BuzzWatch considers that users can fre-
quently update the database and that the document shouldn’t be considered fresh after more than a
13
Hello Web 2.0 World
04_087889 ch01.qxp 5/2/07 12:56 PM Page 13