AJAX Request Flashcards

1
Q

What is used to exchange data with a server?

A

XMLHttpRequest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you send a request to a server?

A

Use the open() and send() methods of the XMLHttpRequest object.

eg. )
xhttp. open(“GET”, “ajax_info.txt”, true);
xhttp. send();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In open(method, url, async), what is the method?

A

The type of request: GET or POST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In open(method, url, async), what is url?

A

The server (file) location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In open(method, url, async), what is async?

A

Either true(asynchronous) or false (synchronous)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The send() method sends the request to the server use for ______.

A

GET

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The send(string) method sends the request to the server used for _____.

A

POST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which is simpler and faster? GET or POST?

A

GET

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When should you use POST?

A
  1. A cached file is not an option(update a file or database on the server)
  2. Sending a large amount of data to the server (POST has no size limitations).
  3. Sending user input (which can contain unknown characters), POST is more robust and secure than GET.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Should you use GET or POST when sending large amount of data to the server? and why?

A

POST because it has no size limits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Should you use GET or POST when sending user input. and why?

A

POST because it is more robust and secure than GET.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the syntax for a simple GET request?

A

xhttp. open(“GET”, url, async);

xhttp. send();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If you get a cached result in your GET request, what should you do?

A

Add a unique ID to the URL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the syntax for a simple POST request?

A

xhttp. open(“POST”, url, async);

xhttp. send();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the ‘setRequestHeader(header, value)

A

Adds HTTP headers to the request

header: specifies the header name
value: specifies the header value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Server requests should be sent _________. and why?

A

Asynchronously because the JavaScript does not have to wait for the server response.

17
Q

By sending a server request asynchronously, the JavaScript can do what?

A
  1. Execute other scripts while waiting for server response.

2. Deal with the response after the response is ready.

18
Q

With the _______ object you can define a function to be executed when the request receives an answer. The function is defined in the __________ property

A

XMLHttpRequest, onreadystatechange

19
Q

Why shouldn’t you use a Synchronous XMLHttpRequest? eg.) async = false.

A

JavaScript will stop executing until the server response is ready. If the server is busy or slow, the application will stop.