JSFiddle - React, Tailwind, and code Playground

by slawe

HTML

<div id="yt_video_title"></div>

JavaScript

var getJSON = function(url, successHandler, errorHandler) {
  var xhr = typeof XMLHttpRequest != 'undefined'
    ? new XMLHttpRequest()
    : new ActiveXObject('Microsoft.XMLHTTP');
  xhr.open('get', url, true);
  xhr.onreadystatechange = function() {
    var status;
    var data;
    // http://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate
    if (xhr.readyState == 4) { // `DONE`
      status = xhr.status;
      if (status == 200) {
        data = JSON.parse(xhr.responseText);
        successHandler && successHandler(data);
      } else {
        errorHandler && errorHandler(status);
      }
    }
  };
  xhr.send();
};
var __video_id = '0UVj_1ABw6U';
getJSON('http://gdata.youtube.com/feeds/api/videos/'+__video_id+'?v=2&alt=jsonc', function(data) {
  document.getElementById('yt_video_title').innerHTML = '<b>Title</b>: ' + data.data.title;
});