How to mount on the received data page via get

Asked

Viewed 35 times

0

I have this line which is a part of the code I’m 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>

Is passing normally.

I have the code that captures the URL data on the other 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 insert this data into the view? I’m using pure js.

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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.