Version 1.7Using glow.net
API Quick Reference
JavaScript is required to use the quick reference
Overview
Glow.net
gives you the ability to send and receive data from the server. Interacting with XML and JSON from the server, you can create highly interactive applications.
A very basic example involves downloading and alerting the values from a dat file:
The example is made from the code below:
Message.dat
MESSAGE FROM THE SERVER
HTML
<input type="button" id="demo1" value="Simple Demo" />
JavaScript
glow.events.addListener("input#demo1", "click", function(event) {
var request = glow.net.get("/glow/docs/1.7/furtherinfo/net/message.dat", {
onLoad: function(response) {
alert(response.text());
}
});
});
Interacting with JSON
You can easily download and process a JSON object:
The example is made from the code below:
programinfo.json
{
program : {
name : "Newswipe",
season : "01",
episode : "06",
nextShowing : {
channel : "´óÏó´«Ã½ Four",
dateTime : "2009-04-30 22:30"
},
description : "Charlie Brooker is back, this time he's got his sights
firmly set on news and current affairs",
categories : [
"satirical",
"current affairs",
"factual"
]
}
}
HTML
<input type="button" id="demo2" value="JSON Demo" />
JavaScript
glow.events.addListener("input#demo2", "click", function(event) {
var request = glow.net.get("/glow/docs/1.7/furtherinfo/net/programinfo.json", {
onLoad: function(response) {
var program = response.json().program;
alert("program " + program.name + "\nseason " + program.season +
", episode " + program.episode);
}
});
});
Interacting with XML
XML is easy to work with:
The example is made from the code below:
programinfo.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<program>
<name>Newswipe</name>
<season>01</season>
<episode>06</episode>
<nextShowing>
<channel>´óÏó´«Ã½ Four</channel>
<dateTime>2009-04-30 22:30</dateTime>
</nextShowing>
<description>Charlie Brooker is back, this time he's got his sights firmly set on news and
current affairs</description>
<categories>
<category>satirical</category>
<category>current affairs</category>
<category>factual</category>
</categories>
</program>
HTML
<input type="button" id="demo3" value="XML Demo" />
JavaScript
glow.events.addListener("input#demo3", "click", function(event) {
var request = glow.net.get("/glow/docs/1.7/furtherinfo/net/programinfo.xml", {
onLoad: function(response) {
var program = response.xml();
alert(
"program " + glow.dom.get(program).get("name").text() +
"\nseason " + glow.dom.get(program).get("season").text() +
", episode " + glow.dom.get(program).get("episode").text()
);
}
});
});
Interacting with other domains
You can access data from other domains using glow.net.loadScript
. Again this is relatively easy, the following code...
HTML
<input type="button" id="demo4" value="Search News Google for 'charlie brooker newswipe'" />
JavaScript
glow.events.addListener("input#demo4", "click", function(event) {
glow.net.loadScript(
"http://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=large&callback
={callback}&start=1&q=charlie%20brooker%20newswipe",
{
onLoad: function(data) {
var results = data.responseData.results;
var output = "Google News Search Results for 'charlie brooker newswipe'\n\n";
for (i in results) {
output += (parseInt(i)+1) + ": " + results[i].titleNoFormatting + "\n";
}
alert(output);
}
}
);
});
... produces this example that interacts with Google's search API:
It is important to note that the object returned in the onload function is not a glow.net.response
object, but an object defined by the domain
that you sent the request to.