From 42fe956843f88e8d50a41be4d2479fad732e8801 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 10 Sep 2017 10:49:59 -0400 Subject: [PATCH] Create json.js --- community/json.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 community/json.js diff --git a/community/json.js b/community/json.js new file mode 100644 index 0000000..65c7517 --- /dev/null +++ b/community/json.js @@ -0,0 +1,25 @@ +var txt = ''; +var xmlhttp = new XMLHttpRequest(); +xmlhttp.onreadystatechange = function(){ + if(xmlhttp.status == 200 && xmlhttp.readyState == 4){ + txt = xmlhttp.responseText; + } +}; +xmlhttp.open("GET","./content/test.json",false); +xmlhttp.send(); +console.log(txt) +var jsona = JSON.parse(txt); +alert(jsona.src); + +if (jsona.type == "img") { + var contenttype = "img" +} else { + var contenttype = "iframe" +} + +var options = ' src = "'; +var options = options.concat(json.src); +var options = options.concat('"'); +var content = document.createElement(contenttype,[options]); + +document.body.appendChild(content)