Facepalm Moments: Android XHR failing

FacepalmAfter searching the whole day to fix a problem with a web app on Android devices, I had a real facepalm moment.

Just in case, you ever stumble across the problem, that your XHR returns successfully, but empty – check the event, which triggers it!

In my case, it was a <a href="#"> tag, styled as a button. The link target of „#“ should effectively do nothing. At least, that’s the case in many browsers like Firefox and Safari (also on the iPhone). But not with Android devices, they know better! (at least with versions 1.5, 1.6 and 2.1)

There, the default action of following the link to ‚#‘ (which is an unnamed anchor on the same page) ends a triggered XHR abrubtely. Android 1.5 and 1.6 will run into Nirvana. Android 2.1 will happily return an empty response, without ever hitting the server.

So, before you start to install Android SDK, analyse the XHR object and try to replace any framework’s XHR wrappers with your own code (like I did) – check, if you succesfully preventDefault() first thing in the event callback function!