diff -r 000000000000 -r 40c8f766c9b8 src/cm/media/js/lib/yui/yui_3.0.0b1/examples/io/io-weather.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/media/js/lib/yui/yui_3.0.0b1/examples/io/io-weather.html Mon Nov 23 15:14:29 2009 +0100 @@ -0,0 +1,406 @@ + + + + + YUI Library Examples: IO: XML Transaction — Retrieving a Yahoo! Weather RSS (XML) Feed via a Server-Side Proxy + + + + + + + + + + + + + + +
+
+
+

+ + YUI 3.x Home - + +

+
+ + +
+ + + +
+
+
+
+

YUI Library Examples: IO: XML Transaction — Retrieving a Yahoo! Weather RSS (XML) Feed via a Server-Side Proxy

+
+
+ +

Note: This is YUI 3.x. Looking for YUI 2.x?

+ +
+
+
+
+ +

IO: XML Transaction — Retrieving a Yahoo! Weather RSS (XML) Feed via a Server-Side Proxy

+ +
+

+

This example demonstrates how to use IO and a PHP proxy — to work around XMLHttpRequest's same-domain policy — to retrieve an XML document from http://xml.weather.yahoo.com/forecastrss.

+ +

To try out the example, fill in your five-digit US zip code, or Location ID.

+ +
+
+ + + + +
+
+ +

Please enter a U.S. Zip Code or a location ID to get the current temperature. The default is Zip Code 94089 for Sunnyvale, California; its location ID is: USCA1116.

+
+
+ +
+ + + + + + + +
+
+
+ +

Exploring the Code for This Example

+ +

Create a YUI instance, using IO, for this example:

+ + + +

Callback Object and the Weather RSS

+

Yahoo! Weather RSS will return an XML document if the transaction is successful. The following success callback handlers is used to process the response.

+ + +

Assemble the Querystring and Initiate the Transaction

+

The Yahoo! Weather RSS feed requires a simple HTTP GET request with a base URL and a querystring containing the required information as a name-value pair. In this example, we will use the following parameter:

+
    +
  • p — location as U.S. Zip Code or Location ID
  • +
+ +

The following are some example location IDs (do not include the city name):

+
    +
  • Beijing: CHXX0008
  • +
  • Helsinki: FIXX0002
  • +
  • London: UKXX0085
  • +
  • Moscow: RSXX0063
  • +
  • Munich: GMXX0087
  • +
  • Paris: FRXX0076
  • +
  • Riyadh: SAXX0017
  • +
  • Tokyo: JAXX0085
  • +
+

For more details on the Yahoo! Weather RSS feed and other location IDs, please visit http://developer.yahoo.com/weather/index.html. +

Function getModule retrieves the input values for location and creates a querystring:

+ + +

Full Script Source

+ +

Here is the full JavaScript source for this example:

+ + + +

Proxy and Response

+

+Once weather.php receives the querystring, it will construct and send an HTTP GET using CURL to retrieve the results from the Yahoo! Weather RSS feed. This allows the transaction to succeed while working around XMLHttpRequest's strict security policy. +

+ +
+ +
+ +
+
+ + + +
+ +
+

Copyright © 2009 Yahoo! Inc. All rights reserved.

+

Privacy Policy - + Terms of Service - + Copyright Policy - + Job Openings

+
+
+ + + +