W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2012

[XHR]

From: Jakub Łopuszański <qbolec@gmail.com>
Date: Sat, 6 Oct 2012 18:09:16 +0200
Message-ID: <CAC=6dzDnk6Ti_tG26tjqhdYgswwYm-uJg8njpW-wUyZzqajT1w@mail.gmail.com>
To: public-webapps@w3.org
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:55 GMT