Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: XMLHttpRequest and Google Chrome Date: Mon, 13 Apr 2015 17:46:31 +0200 Organization: solani.org Lines: 40 Message-ID: References: <130420151317399772%timstreater@greenbee.net> <87h9skyte6.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1428939988 28583 eJwFwQkBACAIA8BKoAwljjzrH8E7bFevYw43EBSsW7kq0zrwTDFDrd0TN3icEtasoOgzbv8pwBGe (13 Apr 2015 15:46:28 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 13 Apr 2015 15:46:28 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 X-User-ID: eJwFwQkRADAIAzBL46BlyOGbfwlLoBS2G0HDw0tItiLPTK1yx813JRHWOqnokneuc+qGTXwznRHA In-Reply-To: Cancel-Lock: sha1:KDt5b+CxLYQAk5qZXk109xRxvEg= X-NNTP-Posting-Host: eJwFwQERADEIAzBLcLTskfMw6l/CEkZ6zkEyQVG27R5gbtf20a3/2x7IDKqlX0Rsm8CZa3oryBHq Xref: csiph.com comp.lang.javascript:27353 Robbie Brown wrote: > On 13/04/15 15:50, Ben Bacarisse wrote: >> Robbie Brown writes: >> >>> there is a common header that is included with every page >>> >>> in the of the common header I have this >>> >>> >> >> This looks wrong. Did you mean 'window.onload=getCart'? The async HTTP >> handler will run when there is no guarantee that the element it will >> modify is present yet. > > But this doesn't work at all as I explained earlier. > If I have a function called getCart() how does getCart call it? > > Obviously I'm missing something here. > > Can anyone put me out of my misery? The onload property of the window element is supposed to hold the reference to a Function object (or null). This function object is automatically called (with a single argument, namely the respective Event object[1]) after the documented has been loaded. In your case you're assigning the return value of getCart() to the property. The return value is undefined, and will be cast to null, so no function will be called when the document has been loaded. Instead getCart is called right before the assignment, which causes the XHR to be triggered immediately. The rest is timing dependend. [1] This argument isn't supplied in old versions of MSHTML. -- Christoph M. Becker