Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Enabling the behavior - retrieving tinderbox status

Our Mozilla extension now exists, but it doesn't do anything. To make it work we have to add JavaScript code that changes its status when the tinderbox status changes. The first step is to write a function that queries the tinderbox server and retrieves the current status.

var gXMLHttpRequest;

function loadTinderboxStatus() {
  gXMLHttpRequest = new XMLHttpRequest();
  gXMLHttpRequest.onload = updateTinderboxStatus;
  gXMLHttpRequest.open("GET", "https://tinderbox.mozilla.org/SeaMonkey/panel.html");
  gXMLHttpRequest.send(null);
}

XMLHttpRequest is an interface in Mozilla for retrieving documents via HTTP. Although it is designed to retrieve XML content and parse it into a DOM, it can retrieve (but not parse) other kinds of content as well. In this case we use it to retrieve an HTML page containing a brief summary of the current tinderbox state. That document gets updated by the tinderbox server every time a build finishes. It displays a list of active tinderbox clients along with the result of their last build attempt.

XMLHttpRequest is easy to use in the simple case we have here. We use new to create a new instance of it, set the instance's onload property to updateTinderboxStatus(), the function we want to execute when the document finishes loading, call its open method with the type of HTTP request we want to make and the URL of the document to retrieve, and then call its send method to send the request.

XMLHttpRequest will retrieve the document located at the given URL and call the updateTinderboxStatus() function when it is done.

Notice that we defined the instance of XMLHttpRequest as a global variable. This is because we need to reference it in the updateTinderboxStatus() function as well as the current function, and we can't pass the object from one function to the other because the one doesn't call the other directly.

Document Tags and Contributors

 Contributors to this page: Sheppy, Kohei, kohei.yoshino
 Last updated by: Sheppy,