function displayData(info) {
document.body.appendChild(document.createElement('pre')).innerHTML = info;
}
function searchInGitHub(str) {
const http = new XMLHttpRequest();
http.open("GET", "https://api.github.com/search/repositories?q=" + str);
http.send();
http.onload = () => {
var result = http.responseText;
var formattedData = JSON.stringify(result, undefined, 4);
displayData(formattedData);
}
}
var result = searchInGitHub('ecommerce');
I am trying to retrieve information from GitHub
repositories. The response is correct, but the data is not being formatted as expected. Kindly review my code and help me resolve this issue. I have tried several solutions, but none seem to work for me!
function searchInGitHub(str) {
const http = new XMLHttpRequest();
http.open("GET", "https://api.github.com/search/repositories?q=" + str);
http.send();
http.onload = () => {
var result = http.responseText;
var formattedData = JSON.stringify(result, undefined, 4);
displayData(formattedData);
}
}
Display Data Function:
function displayData(info) {
document.body.appendChild(document.createElement('pre')).innerHTML = info;
}