I would like to read some data from a GoogleFusion table and then use the results, being new to javascript, I would like to understand how to expose the results so that I can use it globally, here is what I have so far:
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<script src="http://ft2json.appspot.com/api/ft2json.js" type="text/javascript"></script>
<script type="text/javascript">
var results = ft2json.query(
'SELECT * FROM 1j1kKW9s9CrtZ6_o6MdC-xb0YNWb73rQQYENmzQ', /* Fusion Tables query. */
function(result) {
/* Callback function. */
console.log(result);
},
{
/* Optional parameters. */
start : 25,
limit : 50
}
);
console.log('data', results);
</script>
</head>
<body>
</body>
</html>
The first console.log returns the Object, but the second console.log('data', results); returns Undefined.
In the Chrome console the console.log('data', results); is read first, which I don’t understand why?
Here is what happened
The query is asynchronous. So, what happened is that your code keeps running while waiting for the query result. See examples of what you can do below.
Example 1
Example 2