How to mount the page data received via get

0

I have this line which is a part of the code I am using to send the data through the URL:

<a href="curso.html?id=' + item.id +'&descriacao=' + item.descricao + '" 
    class="a-item">'+ item.nome +'</a></div>

It's happening normally.

I have code that captures url data on another page:

  var query = location.search.slice(1);
  var partes = query.split('&');
  var data = {};

  partes.forEach(function (parte) {
  var chaveValor = parte.split('=');
  var chave = chaveValor[0];
  var valor = chaveValor[1];
  data[chave] = valor;
  });

Now how do I enter this data into the view? I'm using pure js.

    
asked by anonymous 20.02.2018 / 18:11

1 answer

2

Create elements in your document and set the textContent for them.

<!-- Dentro do body -->
<script>
   (function() {
      var listEl = document.createElement('ul');
      var idEl = document.createElement('li');
      var descricaoEl = document.createElement('li');

      idEl.textContent = data.id;
      descricaoEl.textContent = data.descricao; 

      document.body.appendChild(listEl);
      listEl.appendChild(idEl);
      listEl.appendChild(descricaoEl);
   })();
</script>
    
20.02.2018 / 18:34