The task: to transfer textual information from blocks one and two to a file of json format, and in order to be able to change it in this json file. That is, to change the text in json it was added or changed in .html

we add to the json file for example instead of "one one one" the text "rantext" and it should change the html file. You just need to remake the html file in html, which will take the text data from the json file and put it in a specific block

I hope clearly explained

Help with this Hello World

<section class="one-section"> <div class="one">one one one</div> </section> <section class="two-section"> <div class="two">two two two</div> </section> 
  • one
    I hope clearly explained - not at all at all. What should be the result? - Grundy Nov.
  • @Bulson it happens that the author does not put a tick. It's okay) - Nick Volynkin

1 answer 1

Here it is possible:

js:

  var settings; function init() { loadJSON(function(response) { settings = JSON.parse(response); }); document.getElementsByClassName('one')[0].innerHTML = settings.one; document.getElementsByClassName('two')[0].innerHTML = settings.two; } function loadJSON(callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType("application/json"); xobj.open('GET', 'settings.json', true); xobj.onreadystatechange = function () { if (xobj.readyState == 4 && xobj.status == "200") { callback(xobj.responseText); } }; xobj.send(null); } 

json (settings.json is next to js):

 {"one":"one one one", "two":"two two two"} 

PS If you use jquery, then there is a special method for getting json from the file:

  $.getJSON('settings.json', function(response){ settings = JSON.parse(response); }) 
  • As a result, the following course of actions was chosen: in the html file in the head, add the following code to the script tag: $(document).ready(function() { $.getJSON('result.json', function(jd) { $('#features3').html('<p> ' + jd.features3 + '</p>'); }); }); further below (already in the body) in the same html file we add an empty block (the text from result will be displayed in it <div class="text_intro" id="features3"></div> result <div class="text_intro" id="features3"></div> result.json { "features3":"Interdum et malesuada fames ac ante..." } Thank you very much for the response - Nick Knightley