Skip to content

Commit 0d99503

Browse files
author
AbdulRahmanDbes
committed
add an explaination about XHR
1 parent d996808 commit 0d99503

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

Week5/REVIEW.MD

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,51 @@ this review covers:
1313

1414
- JavaScript callback functions tutorial: https://www.youtube.com/watch?v=pTbSfCT42_M&index=17&list=WL
1515

16-
## XMLHTtpRequest
17-
**XMLHttpRequest** is an objects to interact with servers. You can retrieve data from a URL without having to do a full page refresh. XMLHttpRequest is used heavily in Ajax programming. - [MDN](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)
16+
## XMLHttpRequest
17+
**XMLHttpRequest** is an objects to interact with servers. You can retrieve data from a URL without having to do a full page refresh. XMLHttpRequest is used heavily in Ajax programming - [MDN](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest).
1818

1919
So what is Ajax?
2020
**Ajax** is a method of exchanging data with a server, and updating parts of a web page without reloading the entire page.
2121

22-
Let's diving a bit deeply into the code:
22+
Let's diving into the code:
2323

24-
First, we need to make an instance from 'XMLHttpRequest' class.
24+
First, we need to make an instance from 'XMLHttpRequest' object.
2525
```javascript
2626
var http = new XMLHttpRequest();
2727
```
2828
When we are doing a request it goes through 5 states:
29-
* 0 : request not initialized.
29+
* 0 : request is not initialized.
3030
* 1 : request has been set up.
3131
* 2 : request has been sent.
3232
* 3 : request is in process.
3333
* 4 : request is complete.
3434

35-
In the code below we are checking if the request is complete or not, and we check the status == 200 just to make sure that we do not get 404 error. - Take a look about [HTTP Status Code](https://httpstatuses.com).
35+
In the code below we are checking if the request is complete or not, and we check the status == 200 just to make sure that we do not get 404 error - Take a look about [HTTP Status Code](https://httpstatuses.com).
3636
```javascript
3737
http.onreadystatechange = function() {
3838
if ( http.readyState == 4 && http.status == 200) {
39-
console.log(`Response from the server: ${http.response}`);
39+
console.log('Response from the server: ' + http.response);
4040
}
4141
}
4242
```
4343
There are methods to deal with a server like (GET, POST, UPDATE, DELETE…)
4444

45-
* GET: to retrieve data from server.
46-
* POST: to send data to server.
47-
* UPDATE: to update data on the server.
48-
* DELETE: to delete date from the server.
45+
* GET: retrieve data from server.
46+
* POST: send data to server.
47+
* UPDATE: update data on the server.
48+
* DELETE: delete date from the server.
4949

50-
To Initialize a request we use [open][https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open] method. The syntax is:
50+
To initialize a request we use [open](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open) method. The syntax is:
5151
```javascript
52-
XMLHttpRequest.open(method, url, async, user, password)
52+
XMLHttpRequest.open(method, url, async, user, password);
5353
```
54-
The parameters 'method' and 'url' are mandatory, 'user' and 'password' are optional. True is a default value for 'async'.
54+
The parameters _method_ and _url_ are mandatory, _user_ and _password_ are optional. True is a default value for _async_.
5555

5656
```javascript
5757
http.open("GET", URL, true/false);
5858
```
59-
At the end we have to send our request to the server through [send](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send) method. In our situation we are retriving a data from the server, so we do not have to pass any parameter to the send request.
59+
At the end we have to send our request to the server through [send](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send) method. In our situation we are retrieving a data from the server, so we do not have to pass a parameter to the send request.
6060

6161
```javascript
62-
http.send()
62+
http.send();
6363
```

0 commit comments

Comments
 (0)