Method & URL
Opening a request requires specifying the HTTP method you’ll use to send the request and the URL you’ll send the request to.
xhr.open('GET', 'sidebar.html');
Method
POST
- Sends its data in the "body" of the request.
- When you want to send data that the web server should store in a database.
- When you want to send more than 2083 characters of data to the web server.
GET
- Sends data in the URL itself.
- When you’re only interested in getting information from a web server.
URL
But with AJAX, we frequently want more than just a static file of text or HTML like sidebar.html
. We’re after dynamic, that is, changing information.
For a server site program to send you customized information, you need to send the server extra information. You can do this by adding data to the end of the URL sent to the server, called a query string.
Query String
The part after the question mark is called a query string, and it’s a way to send additional information that a web server can use to control the output of it’s response.
Example 1
http://website.com/employees.php?firstName=Rita&lastName=Johns
Example 2
http://server.com/page.php?name=Johnny+Depp&movie=Pirates+of+the+Caribbean%3A+Dead+Man%27s+Chest
+
is replaced with space. It is one among many other escaped characters.