Skip to content
Permalink
1eb2371f13
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
38 lines (33 sloc) 1.27 KB
function searchUsers() {
const searchInput = document.getElementById('searchInput').value;
if (searchInput.length < 1) {
alert('Please enter a username');
return;
}
const apiUrl = `https://github.uconn.edu/api/v3/search/users?q=${searchInput}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
const results = document.getElementById('results');
const resultsCount = document.getElementById('resultsCount');
results.innerHTML = '';
resultsCount.innerText = `Found ${data.total_count} result(s).`;
data.items.forEach(user => {
const userElement = document.createElement('div');
userElement.innerHTML = `
<div class="card">
<img src="${user.avatar_url}" class="card" alt="Avatar">
<div class="card-body">
<h5 class="card-title">${user.login}</h5>
<a href="${user.html_url}" class="btn btn-primary" id="profilebtn">View Profile</a>
</div>
</div>
`;
results.appendChild(userElement);
});
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred. Please try again.');
});
}