// Create a table-building function that will accept some JSON data from http://jsonplaceholder.typicode.com
// and generate a table with all the trimmings
//
// Since native XHR is a pain, the reqwest library is made available in this fiddle. Docs on how to use it are here:
// https://github.com/ded/reqwest
//
// It should:
// - build a <thead> element, with the appropriate <th> elements
// - build a <tbody> element
// - request data from the server, and create a <tr> for each item in the response (add as many columns as you like)
// - include an "actions" column for buttons
// - add a "remove" button in the actions column which, when clicked, will send a DELETE request to the server,
// and remove the row when successful
//
// BONUS 1: Create a form to add new rows to the table. when the form is submitted, it sends a POST request with
// the form's data and, when the XHR is successful, adds the row to the table.
// BONUS 2: Limit the number of returned rows in each request to 10, and add pagination UI in a <tfoot> element
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i]);
}
}
}
var el = document.getElementById('postCodeInput');
var postCode,
url;
function getWeatherReport() {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.addEventListener('load', function xhrLoad(e) {
var tbody, data, output = '';
if (xhr.status === 200) {
data = JSON.parse(xhr.responseText);
// update the header row
document.getElementById('header').innerHTML = data.query.results.channel.item.title;
// grab just the conditions node
conditions = data.query.results.channel.item.condition;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.