Datasheet

12:18:32 200 GET /buzzwatch/watch.php?name=jw-a (application/xml)
12:18:32 200 GET /buzzwatch/yahoo_quotes.php?tag=jw-a (application/xml)
12:18:32 200 GET /buzzwatch/yahoo_chart.php?tag=jw-a&
date=Sat%20Jul%2022%202006%2012:18:32%20GMT+0200%20(CEST) (image/png)
12:18:33 200 GET /buzzwatch/yahoo_finance_news.php?tag=jw-a (application/xml)
12:18:34 200 GET /buzzwatch/yui/menu/assets/menuchk8_dim_1.gif (image/gif)
12:18:33 200 GET /buzzwatch/delicious.php?tag=wiley (application/xml)
Note that the line break between jw-a& and date= has been added for readability reasons and is not pre-
sent in the servers log.
This new burst of exchanges is triggered by clicking one of the menu items that were added dynami-
cally. The action registered to this click is a call to the
loadSymbol method in controller.js:
BuzzWatchController.prototype.loadSymbol = function(e, o, symbol) {
YAHOO.buzzWatch.menuGo.cfg.getProperty(“submenu”).hide();
YAHOO.buzzWatch.controller.load(symbol);
}
This method is what you would call in other programming languages a static or a class method: it
isn’t called in the context of an object or, in other words, the
this object isn’t available. It hides the Go
submenu and calls the instance method
load of the controller. This method is hardly more complicated:
BuzzWatchController.prototype.load = function(symbol) {
if (symbol != undefined)
this.symbol = symbol;
if (this.symbol != undefined) {
YAHOO.util.Connect.asyncRequest(‘GET’, “watch.php?name=”+this.symbol,
this.callback);
}
}
Its main action is the call to the YAHOO.util.Connect.asyncRequest that you already know. This call
is what explains the first line in the server’s log and fetches the definition of the watch that has been
requested by the user. The request that is transmitted over the wire by this instruction is:
GET /buzzwatch/watch.php?name=jw-a HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.0.4) Gecko/20060608
Ubuntu/0.9.3 (Ubuntu) StumbleUpon/1.909 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-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
It’s time to replace your JavaScript hat with your PHP one. Server side, this uses the same watch.php
script that you already know. The difference is that this time you fall in the second branch of the multi-
ple
if...then...else statement:
} else if ($_GET[‘name’]) {
readOne();
17
Hello Web 2.0 World
04_087889 ch01.qxp 5/2/07 12:56 PM Page 17