-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (35 loc) · 1.31 KB
/
app.js
File metadata and controls
37 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function loadAllSuperheroes() {
fetch('superheroes.php')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
document.getElementById('output').innerHTML = data;
})
.catch(error => {
console.error('Error fetching superheroes:', error);
document.getElementById('output').innerHTML = '<p>Failed to load superhero data.</p>';
});
}
document.getElementById('searchButton').addEventListener('click', function() {
const query = encodeURIComponent(document.getElementById('searchInput').value.trim());
document.getElementById('output').innerHTML = '';
fetch(`superheroes.php?query=${query}`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
document.getElementById('output').innerHTML = data;
})
.catch(error => {
console.error('Error fetching superhero:', error);
document.getElementById('output').innerHTML = '<p>Failed to load superhero data.</p>';
});
});
window.onload = loadAllSuperheroes;