<%= javascript_include_tag 'prototype' %>

<script type="text/javascript">

function queryTwitter() {
  var req = new Ajax.Request("http://search.twitter.com/trends.json", {
          method: 'GET', 
          onFailure: function(request) {
            alert('AJAX doesnt work.');
          }, 
          onComplete: function(request) {
            receiveTwitterResponse( request.responseText);
          }
      });
}

function receiveTwitterResponse(results) {
  var result = JSON.parse(results);
  var point = document.getElementById('twittertrends');
  for (var i = 0; i < result.trends.length; i++) {
    point.append(document.createTextNode( result.trends[i].name ));
  }
}

Event.observe(window, 'load', function() {
  alert('page loaded');
  queryTwitter();
});

</script>
<h1>Current Twitter Trends</h1>
<div id="twittertrends">
</div>
<div id="status">
</div>

<%= javascript_include_tag 'prototype' %>

<script type="text/javascript">

function queryTwitter() {
  var req = new Ajax.Request("http://search.twitter.com/trends.json", {
          method: 'GET', 
          onFailure: function(request) {
            alert('AJAX doesnt work.');
          }, 
          onComplete: function(request) {
            receiveTwitterResponse( request.responseText);
          }
      });
}

function receiveTwitterResponse(results) {
  if (results != "") {
    showStatus("done.");
    var result = JSON.parse(results);
    var point = document.getElementById('twittertrends');
    for (var i = 0; i < result.trends.length; i++) {
      point.append(document.createTextNode( result.trends[i].name ));
    }
  }
  else {
    showStatus("Bad AJAX results");
  }
}

function showStatus(message) {
  var status = document.getElementById('status');
  status.innerHTML = message;
}

Event.observe(window, 'load', function() {
  showStatus("Querying twitter...");
  queryTwitter();
});

</script>
<h1>Current Twitter Trends</h1>
<div id="twittertrends">
</div>
<div id="status">
</div>

Make sure the page doesn't crash when loading if we get a duff AJAX response.
Make sure the page doesn't crash when loading if we get a duff AJAX response.
