diff -r 322d0feea350 -r 89ef5ed3c48b src/cm/media/js/lib/yui/yui_3.10.3/docs/yql/simple-yql.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/yql/simple-yql.html Tue Jul 16 14:29:46 2013 +0200 @@ -0,0 +1,199 @@ + + + + + Example: Simple YQL Query + + + + + + + + + + +
+
+

+
+ + +

Example: Simple YQL Query

+
+
+
+
+

In this example, we make a simple YQL Query to retrieve data from the Yahoo! Weather YQL table.

+
+ +
+ + + +
Querying YQL..
+ + + + + +
+ +

The easiest way to build a YQL query is by visiting the YQL Console. In this example we will be using the weather.forecast table. The YQL statement that we are using looks like this:

+ +
select * from weather.forecast where location=90210
+ + +

You can preview this query in the YQL Console to get a sense of the data it returns.

+ +

Setting Up the YUI Instance

+ +

Now we need to create our YUI instance and tell it to load the yql and node modules.

+ +
YUI().use('node', 'yql');
+ + +

Making the Query

+ +

We now have a YUI instance with the yql module (and its dependencies) attached, so we can proceed to make a query.

+ +
YUI().use('node', 'yql', function(Y) {
+    
+    var res = Y.one('#res'),
+        zip = '90210';
+    
+    Y.YQL('select * from weather.forecast where location=' + zip, function(r) {
+        var el = Y.Node.create('<div class="mod"></div>');
+
+        el.set('innerHTML', '<h2>Weather for ' + zip + '</h2>' + r.query.results.channel.item.description);
+
+        res.setHTML(el);
+    
+    });
+});
+ +
+
+
+ +
+ +
+
+
+ + + + + + + + + + +