Please watch the first 45 mins of the Ajax Crash Course by Traversy Media (see link below).
The example code in this course is using on ES5 syntax. In the ajaxcrash folder in this repo you will find updated example code (ajax1 to ajax3) that use the ES6 syntax and styling that we prefer in HYF. Specifically, the following changes have been made:
- The JavaScript code has been placed in a separate file, loaded with a
<script>tag from the HTML file. - Instead of var to declare a variable, const and let are used.
- The non-strict equality operator
==has been replaced with the strict version===. - Functions are defined before they are used.
- Anonymous functions use the arrow syntax instead of the function keyword. Consequently, the
thisvalue inside the XMLHttpRequest event handlers have been replaced with thexhrvariable name. - The
for...inloops for iterating through an array have been replace withfor...of.
Watch this YouTube video up until the PHP examples (the first 45 mins):
- Traversy Media - Ajax Crash Course