Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.karotte.org!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1847393.YeQSDktdzs@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 06 Sep 2012 21:49:32 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <10463793.jXXL31m3yW@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 51 NNTP-Posting-Date: 06 Sep 2012 21:49:33 CEST NNTP-Posting-Host: 4110b6fa.newsspool3.arcor-online.net X-Trace: DXC=;EnMg>210XLk:C4l9A;OcOMcF=Q^Z^V3H4Fo<]lROoRA8kF Stefan Weiss wrote: >> […] >> function fetch (url, callback) { >> // (minimal example) >> var xhr = new XMLHttpRequest(); >> xhr.open("GET", url, true); >> xhr.onreadystatechange = function () { >> if (xhr.readyState == "4") { >> callback(xhr.responseText); >> } >> }; >> xhr.send(); >> } >> […] >> >> What am I missing? > > At first glance, that the `readyState' property values are of type Number, > and that xhr.send(null) should be called with GET. At second glance, that readyState == 4 does not need to mean success (you have to check the `status' as well) and that `callback' has no idea whether an empty `responseText' means success or failure. I think that should be fixed even in a minimal XHR example: function fetch (url, callback) { /* (minimal example) */ var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { callback(xhr.responseText); } }; xhr.send(null); } BTW, it is acceptable to see that you also use the space-before-parameter- list convention. It makes calls so much easier to find, does it not? PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16