112k views
4 votes
suppose you are writing javascript code to send an asynchronous get request to the action.pl file on the server. you have written code that defines your request. which statement should you use next to send it to the server?

User Jstedfast
by
8.1k points

1 Answer

4 votes

Answer:

To send the asynchronous GET request to the server, you should use the `XMLHttpRequest.send()` method. Here is an example:

```javascript

const xhr = new XMLHttpRequest();

xhr.open('GET', 'action.pl', true);

xhr.onreadystatechange = function() {

if (xhr.readyState === 4 && xhr.status === 200) {

// do something with the response

}

};

xhr.send();

```

In this example, `xhr.open()` is used to define the request and `xhr.onreadystatechange` is used to define a function that will be called when the response is received. The `xhr.send()` method is then called to actually send the request to the server.

Step-by-step explanation:

please follow me for more if you need any help

User Hyperbole
by
8.5k points