jQuery connections to YQL data

The team I’m mentoring/training at the FT are going to be transferring from Flash/ActionScript to HTML5 JavaScript CSS3. So here are some of the code examples I’ve given them for usage when connecting to remote data.

Fro XML only and no CORS.

$(document).ready(function(){
$.get(‘FT500dataset2.xml’, function(data){
$(data)
.find(‘dataset > dataUnit’)
.each(
function(i){
alert(‘position=’ + i);
}
);
});
});

For JSONP-X

$(document).ready(function(){

var yql = ‘http://query.yahooapis.com/v1/public/yql?q=’;
yql += encodeURIComponent(“select * from xml where url=’” + rData + “‘”);
yql += ‘&format=xml&diagnostics=true&callback=?’;

$.getJSON(yql,function(ds){
})

.success( function(data){

alert($(data.query.results));
});
});

For straight JSON

$(document).ready(function(){

var yql = ‘http://query.yahooapis.com/v1/public/yql?q=’;
yql += encodeURIComponent(“select * from xml where url=’” + rData + “‘”);
yql += ‘&format=json&diagnostics=true&callback=?’;

$.getJSON(yql,function(ds){
})

.success( function(data){

$(data.query.results.dataset.dataUnit)
.each(
function(i){
alert(‘position=’ + i);
}
);
});
});

This entry was posted in html, javascript, user tools, YQL. Bookmark the permalink.