[XHR]

Spec at http://www.w3.org/TR/XMLHttpRequest/ says that:
1. each change of state must fire an event
2. readyState must always be equal to the current state
it follows that it is possible for eventhandler to be called more than once
with the same value of readyState, in particular the code example [1] which
can be found in the spec is buggy, as it only checks if readyState is 4,
but does not check if this value was already reported before.
This example seems to inspire a vast number of developers, in particular
OpenSocial seems to suffer from it.

Best regards,
Jakub Łopuszański

[1]

Some simple code to do something with data from an XML document fetched
over the network:

function processData(data) {
  // taking care of data
}

function handler() {
  if(this.readyState == this.DONE) {
    if(this.status == 200 &&
       this.responseXML != null &&
       this.responseXML.getElementById('test').textContent) {
      // success!
      processData(this.responseXML.getElementById('test').textContent);
      return;
    }
    // something went wrong
    processData(null);
  }
}

var client = new XMLHttpRequest();
client.onreadystatechange = handler;
client.open("GET", "unicorn.xml");
client.send();

Received on Monday, 8 October 2012 08:17:19 UTC