Skip to content

Instantly share code, notes, and snippets.

@paulusm
Created November 20, 2018 15:54
Show Gist options
  • Save paulusm/6ecc863f6549e02a07b2a2faba22d215 to your computer and use it in GitHub Desktop.
Save paulusm/6ecc863f6549e02a07b2a2faba22d215 to your computer and use it in GitHub Desktop.
var getFeedForTag = function(){
//Get the selected form options
var selectedTag = document.getElementById("tag");
console.log("Selected tag - " + selectedTag.value);
// Build our API URL
var mixUrl = "https://api.mixcloud.com/search/?q="+ selectedTag.value + "&type=tag";
//Create the request
var req = new XMLHttpRequest();
//Function to run when we have a result back
req.onloadend = function (){
document.getElementById("results").innerHTML = "";
//Get the JSON data
mcData = JSON.parse(req.responseText);
//Loop through the data and create an A tag inside a UL tag
// For each sub tag.
for(var i=0; i<mcData.data.length; i++){
var listItem = document.createElement("li");
var tagLink = document.createElement("a");
tagLink.setAttribute("href", mcData.data[i].url);
tagLink.innerText = mcData.data[i].name;
listItem.appendChild(tagLink);
document.getElementById("results").appendChild(listItem);
}
};
req.open("GET",mixUrl);
req.send();
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment