0% found this document useful (0 votes)
8 views1 page

Pokémon Data Fetching Script

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Pokémon Data Fetching Script

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

$(document).

ready(function () {
$("#searchButton").click(function () {
var pokemonName = $("#pokemonName").val();
getData(pokemonName);
});
});

function getData(searchData) {
$.ajax({
url: `[Link]
type: "GET",
dataType: "json",
success: function (data) {
displayData(data);
},
error: function (jqXHR, textStatus, errorThrown) {
$("#pokemonData").html("Pokémon not found!");
},
});
}

function displayData(data) {
var html = "";
html += `<div class="max-w-xs mx-auto bg-white shadow-md rounded-lg overflow-
hidden mt-4">
<img class="w-full h-auto" src="${[Link].front_default}"
alt="${[Link]}">
<div class="p-4">
<h2 class="text-xl font-semibold mb-2 uppercase">$
{[Link]}</h2>
<p class="text-gray-600">Height: ${[Link]}</p>
<p class="text-gray-600">Weight: ${[Link]}</p>
<p class="text-gray-600">Type: ${[Link][0].[Link]}</p>
<p class="text-gray-600">Number: ${[Link]}</p>
</div>
</div>`;
$("#pokemonData").html(html);
}

You might also like