Except as otherwise noted,
the content of this page is licensed under the Creative Commons
Attribution 3.0 License.
Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
StockWatcher/war folder.stockPrices.php
<?php
header('Content-Type: text/javascript');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
define("MAX_PRICE", 100.0); // $100.00
define("MAX_PRICE_CHANGE", 0.02); // +/- 2%
echo '[';
$q = trim($_GET['q']);
if ($q) {
$symbols = explode(' ', $q);
for ($i=0; $i<count($symbols); $i++) {
$price = lcg_value() * MAX_PRICE;
$change = $price * MAX_PRICE_CHANGE * (lcg_value() * 2.0 - 1.0);
echo '{';
echo "\"symbol\":\"$symbols[$i]\",";
echo "\"price\":$price,";
echo "\"change\":$change";
echo '}';
if ($i < (count($symbols) - 1)) {
echo ',';
}
}
}
echo ']';
?>
or run the ant build script to create the web mode files for the application (which will now include stockPrices.php). 
http://localhost/StockWatcher/stockPrices.php?q=ABC+DEF
[{"symbol":"ABC","price":40.485578668179,"change":-0.53944918844604},
{"symbol":"DEF","price":1.3606576154209,"change":0.0051755221198266}]Now that you can retrieve JSON-encoded stock data from the server, continue with the next step in the JSON tutorial, Manipulating JSON data in the client-side code.