title: fusion tables - Calling the API from a browser using JavaScript - uncaught typeError
body: <p>I am trying to get some data out of a Google Fusion Table.</p>
  
  <p>I have used the Google documentation to produce a JSON file using by calling the Fusion Tbales API like so: 
  <a href="https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20" rel="nofollow">https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20</a>*%20FROM%yyyyyy&amp;key=xxxxxxxxx"</p>
  
  <p>I now what to incorporate this call into a webpage and display the results on the same  page.</p>
  
  <p>I have followed the instructions on this page which gives some example code (Calling the API from a browser using JavaScript):
  <a href="https://developers.google.com/fusiontables/docs/v1/getting_started#JS" rel="nofollow">https://developers.google.com/fusiontables/docs/v1/getting_started#JS</a></p>
  
  <p>I have put the code on my site and replaced the script call with the one from the top of this post.</p>
  
  <p>When I view the page nothing displays on the page and i get an error in the Google console saying: Uncaught TypeError: Cannot read property 'length' of undefined </p>
  
  <p>Does any one know of a better example or tutorial on this where the example code works?</p>
  
  <p>OR </p>
  
  <p>Does any on know why this script is failing?</p>
  
  <p>The code:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Google Fusion Tables API Example&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="content"&gt;&lt;/div&gt;
      &lt;script&gt;
      function handler(response) {
        for (var i = 0; i &lt; response.items.length; i++) {
          var item = response.items[i];
          // Either show the body or the automatic columns of the template
          if (item.body) {
            document.getElementById("content").innerHTML += "&lt;br&gt;" + item.body;
          } else {
            for (var j = 0; j &lt; item.automaticColumnNames.length; j++) {
              document.getElementById("content").innerHTML += "&lt;br&gt;" + item.automaticColumnNames[j];
            }
          }
        }
      }
      &lt;/script&gt;
   &lt;script src="https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%20xxxxq5TFqB4oM-HCQBkRqzOM6uC2qAIJDk91Q&amp;keyXXXXXXXX"&gt;&lt;/script&gt;
  
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>