Event Listeners

Common targets are Element, or its children, Document, and Window, but the target may be any object that supports events, such as XMLHttpRequest.
The event listener can be specified as either a callback function or an object that implements EventListener, whose handleEvent() method serves as the callback function.


The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

The type of request is dictated by the optional async argument (the third argument) that is set on the XMLHttpRequest.open() method.
If this argument is true or not specified, the XMLHttpRequest is processed asynchronously, otherwise the process is handled synchronously.

function reqListener () { 

var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "https://bettersolutions.com/example.txt", true);


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext