AJAX Request Flashcards
What is used to exchange data with a server?
XMLHttpRequest
How do you send a request to a server?
Use the open() and send() methods of the XMLHttpRequest object.
eg. )
xhttp. open(“GET”, “ajax_info.txt”, true);
xhttp. send();
In open(method, url, async), what is the method?
The type of request: GET or POST
In open(method, url, async), what is url?
The server (file) location
In open(method, url, async), what is async?
Either true(asynchronous) or false (synchronous)
The send() method sends the request to the server use for ______.
GET
The send(string) method sends the request to the server used for _____.
POST
Which is simpler and faster? GET or POST?
GET
When should you use POST?
- A cached file is not an option(update a file or database on the server)
- Sending a large amount of data to the server (POST has no size limitations).
- Sending user input (which can contain unknown characters), POST is more robust and secure than GET.
Should you use GET or POST when sending large amount of data to the server? and why?
POST because it has no size limits
Should you use GET or POST when sending user input. and why?
POST because it is more robust and secure than GET.
What is the syntax for a simple GET request?
xhttp. open(“GET”, url, async);
xhttp. send();
If you get a cached result in your GET request, what should you do?
Add a unique ID to the URL.
What is the syntax for a simple POST request?
xhttp. open(“POST”, url, async);
xhttp. send();
What is the ‘setRequestHeader(header, value)
Adds HTTP headers to the request
header: specifies the header name
value: specifies the header value