what does "result is delivered using events" mean?

Asked 2 months ago
Viewed 9 times

I was reading about send method of XMLHttpRequest on mdn web docs.

I could'nt understand what does "result is delivered using events mean"

If the request is asynchronous (which is the default), this method returns as soon as the request is sent and the result is delivered using events. If the request is synchronous, this method doesn't return until the response has arrived.

asked 2 months ago

Correct Answer

That means that you have to add a event listener to the XMLHttpRequest object that will the event when the process has finished.
The example there already shows this.

answered 2 months ago

Other Answer

The MDN docs refer to these events:, specifically the onload and onreadystatechange events.

From their GET example:

const xhr = new XMLHttpRequest();'GET', '/server', true);

// "onload" is the event and executes the arrow function when triggered.
xhr.onload = () => {
  // Request finished. Do processing here.

answered 2 months ago