Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta http-equiv="X-UA-Compatible" content="ie=edge" />
- <title>Document</title>
- <script
- src="https://code.jquery.com/jquery-3.4.1.min.js"
- integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
- crossorigin="anonymous"
- ></script>
- </head>
- <body>
- <h1>Pokemon Api Tests</h1>
- <section>
- <h1>Pokemons</h1>
- <ol id="lista-pokemon">
- </ol>
- </section>
- </body>
- </html>
- <script>
- const apiUrl = 'https://pokeapi.co/api/v2/';
- /**
- * @param {number} id
- * @returns {JQueryXHR}
- */
- function getPokemonById(id) {
- var url = apiUrl + 'pokemon/' + id.toString();
- return $.get(url);
- }
- /**
- * @param {string} name
- * @returns {JQueryXHR}
- */
- function getPokemonByName(name) {
- var url = apiUrl + 'pokemon/' + name;
- return $.get(url);
- }
- /**
- * @param {Object} data
- */
- function updateList(data, status) {
- var lista = $('#lista-pokemon');
- lista.append(
- $('<li>', { text: data.name })
- );
- console.log(data);
- }
- function fail(error, status) {
- console.error('Status: ' + status);
- console.error(error);
- }
- $(function () {
- wantToQuery = [1, 2, 3, 4, 5, 6, 7, 8, 9];
- wantToQuery.forEach(elem => {
- var call = getPokemonById(elem);
- call.then(updateList, fail);
- });
- })
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement