Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadJSON(callback)
- {
- var xobj = new XMLHttpRequest();
- xobj.overrideMimeType("application/json");
- xobj.open('GET', 'http://someurl', true);
- xobj.onreadystatechange =
- function () {
- if (xobj.readyState == 4 && xobj.status == "200") {
- callback(xobj.responseText);
- }
- };
- xobj.send(null);
- }
- function requestJSON()
- {
- loadJSON(
- function(response) {
- data = JSON.parse(response);
- }
- );
- }
- $(document).on("click", "a", function()
- {
- //this == the link that was clicked
- var href = $(this).attr("href");
- var href_id = $(this).attr("id");
- if (href_id == "getdata")
- {
- loadJSON(function(response)
- {
- var div_showdata = document.getElementById('showdata');
- div_showdata.innerHTML = "Data";
- var content = "<ul class='box3'>";
- // Parse JSON string into object
- data = JSON.parse(response);
- for (var key in data)
- {
- content += ("<li>" + key + " : " + data[key] + "</li>");
- }
- content += "</ul>";
- //var first = "Some text";
- //var test_output = "<p>" + first + "</p>";
- div_showdata = document.getElementById('showdata');
- div_showdata.innerHTML = content;
- });
- console.log("You've clicked link:" + href);
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment