AJAX with Safari

Mental note to myself:

When making a POST request with XMLHttprequest and Safari(v2.0.4), always generate some content for the browser.

If not, the status will always be undefined.
example:

if (!$mysqli->query($insert)) {
  trigger_error("error writing data: ".$insert);
  exit;
}
else {
  echo "0";
}

This costed me some hours pulling my hair….
The following javascript works like a charm when you return a “0″ at the end of the php file called with POST. If you don’t return anything, Safari will decide that the HTTP headers are undefined and thus call the error handler.

KwAjax.ContentLoader.onReadyState=function(){
  var req=this.req;
  var ready=req.readyState;
  if (ready==KwAjax.READY_STATE_COMPLETE){
      var httpStatus=req.status;
      if (httpStatus == 200 || httpStatus == 0) {
        this.onload.call(this);
      }
      else {
        this.onerror.call(this);
      }
  }
}
 

Gargleblaster.org

My latest run

date: 30 Nov 08 11:02 CET
distance: 4.95 km
duration: 28'04"
my last run

All my runs

total runs: 66
total km: 355.11
total time: 37:06'19"
farthest run: 11.13 km