You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -905,24 +905,24 @@ fetchingPosts
905
905
906
906
#### Explanation
907
907
908
-
When you do an *AJAX request* the response is not synchronous because you want a resource that takes some time to come. It even may never come if the resource you have requested is unavailable for some reason (404).
908
+
When you do an *Ajax request* the response is not synchronous because you want a resource that takes some time to come. It even may never come if the resource you have requested is unavailable for some reason (404).
909
909
910
910
To handle that kind of situations, ES2015 has given us *promises*. Promises can have three different states:
911
911
912
912
- Pending
913
913
- Resolved
914
914
- Rejected
915
915
916
-
Let's say we want to use promises to handle an AJAX request to fetch the resource X.
916
+
Let's say we want to use promises to handle an Ajax request to fetch the resource X.
917
917
918
918
##### Create the promise
919
919
920
-
We firstly are going to create a promise. We will use the jQuery get method to do our AJAX request to X.
920
+
We firstly are going to create a promise. We will use the jQuery get method to do our Ajax request to X.
921
921
922
922
```js
923
923
constxFetcherPromise=newPromise( // Create promise using "new" keyword and store it into a variable
924
924
function(resolve, reject) { // Promise constructor takes a function parameter which has resolve and reject parameters itself
925
-
$.get("X") // Launch the AJAX request
925
+
$.get("X") // Launch the Ajax request
926
926
.done(function(X) { // Once the request is done...
927
927
resolve(X); // ... resolve the promise with the X value as parameter
928
928
})
@@ -951,7 +951,7 @@ xFetcherPromise
951
951
})
952
952
```
953
953
954
-
```.then``` is a method that once called will put the xFetcherPromise in **pending** state. When called, the promise body runs and in this case an AJAX call is being done.
954
+
```.then``` is a method that once called will put the xFetcherPromise in **pending** state. When called, the promise body runs and in this case an Ajax call is being done.
955
955
956
956
If it succeeds, *resolve* is called and the function passed as ```.then``` parameter is executed.
0 commit comments