Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36543
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Deregistering an AJAX handler |
| Date | 2019-05-02 00:20 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <dc33778a-64cb-baa0-2f06-3e9de25318b5@PointedEars.de> (permalink) |
| References | <666b28b5-b96b-404b-87fc-6233f492fc0d@googlegroups.com> <slrnqcjb43.4u8.jon+usenet@sable.unequivocal.eu> <4068e3d5-44dd-84f6-ae93-27ba20346fcd@PointedEars.de> <slrnqcjp5n.4u8.jon+usenet@sable.unequivocal.eu> |
Jon Ribbens wrote:
> On 2019-05-01, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> Jon Ribbens wrote:
>>> var handler = function () { ... }
>>> var request = new XMLHttpRequest()
>>> request.onreadystatechange = function () { if (handler) handler() }
>>> request.open('GET', 'http://localhost:8080')
>> This does not work reliably; in the worst case, .open(…) will *reset* the
>> event-handler property value that was just assigned. .open(…) must be
>> called *before* assigning to the event-handler properties.
>
> Oh, ok. In general it seems better to set event handlers before
> calling the method that will lead to the events being raised, but
> I am sure you are right that this old and shonky API has many
> imperfections.
I do not think that the described behavior is an "imperfection", but by
design; and this API is not old:
<https://xhr.spec.whatwg.org/>
However, it should be noted that in the latest revision of the API (i.e., at
the time of writing) a “readystatechange” event is to be fired as the last
step in the “.open(…)” algorithm. It is not obvious whether the
event-handler attributes are to be reset as well; however, this indicates
that they are not to be reset, and if so, then assigning to
“.onreadystatechange” before calling “.open(…)” will cause the referenced
function to be called, which is usually not wanted.
That “.open(…)” calls the event listener might be the reason why the OP
wants to reset the latter: they might have assigned to the property before
and have difficulties handling this additional .open(…) call. However, as I
indicated, doing this with window.setTimeout(…) *outside* the event listener
is conceptually *wrong: It would produce a race condition dependent on the
load of the client and server systems, and the network connection.
>>> setTimeout(function () { handler = function () { ... } }, 10000)
>>
>> Such nonsense, it is not even wrong.
>
> It's neither nonsense nor wrong.
It is *most definitely* nonsense because the request is (to be) processed
*asynchronously*.
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Deregistering an AJAX handler groovee@cyberdude.com - 2019-05-01 06:17 -0700
Re: Deregistering an AJAX handler Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-01 16:21 +0200
Re: Deregistering an AJAX handler groovee@cyberdude.com - 2019-05-01 08:51 -0700
Re: Deregistering an AJAX handler Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-01 19:58 +0200
Re: Deregistering an AJAX handler "Mark-" <nospam@mapson.xyz> - 2019-05-02 00:56 +0000
Re: Deregistering an AJAX handler Julio Di Egidio <julio@diegidio.name> - 2019-05-01 09:32 -0700
Re: Deregistering an AJAX handler Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-05-01 14:26 +0000
Re: Deregistering an AJAX handler groovee@cyberdude.com - 2019-05-01 08:42 -0700
Re: Deregistering an AJAX handler Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-05-01 15:50 +0000
Re: Deregistering an AJAX handler groovee@cyberdude.com - 2019-05-01 08:58 -0700
Re: Deregistering an AJAX handler Julio Di Egidio <julio@diegidio.name> - 2019-05-01 09:07 -0700
Re: Deregistering an AJAX handler Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-01 20:03 +0200
Re: Deregistering an AJAX handler Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-05-01 18:25 +0000
Re: Deregistering an AJAX handler Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-02 00:20 +0200
Re: Deregistering an AJAX handler Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-05-02 10:29 +0000
Re: Deregistering an AJAX handler Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-03 03:58 +0200
Re: Deregistering an AJAX handler Julio Di Egidio <julio@diegidio.name> - 2019-05-01 08:28 -0700
Re: Deregistering an AJAX handler groovee@cyberdude.com - 2019-05-01 08:44 -0700
Re: Deregistering an AJAX handler Julio Di Egidio <julio@diegidio.name> - 2019-05-01 09:01 -0700
csiph-web