A Primer to Using Air – Followup

Well, I poked around in the AIR documentation, and I think I found their preferred method (and the only method I tried that would let me grab data from another domain) of connecting to a backend script:

[cc lang=”javascript”]

function appLoad(){
var request = new air.URLRequest(‘http://www.php.net/news.rss’);
var loader = new air.URLLoader();
loader.dataFormat=air.URLLoaderDataFormat.TEXT;
loader.addEventListener(air.Event.COMPLETE,completeHandler);
loader.load(request);
}
function completeHandler(event){
var loader2=event.target;
air.trace(loader2.data);
alert($(‘//rdf/item/title’,loader2.data).length);

$(loader2.data).find(‘item/title’).each(function(k,v){
alert(v.text());
});

$(‘item’,loader2.data).each(function(k,v){
$(‘#mytbdy’).append(‘

> ‘+v.childNodes[0].nodeValue+’

‘);
});
}

[/cc]

I think the code above’s a little flaky when it comes to inserting things back into the table, but the connection code is sound. It grabs the actual RSS file from php.net and pushed it into the table below it.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s