0
I have a task where I need to create a registry for users, save in the Log location and then in a list show on the site all registered users. I was able to save the user data, but I’m having problems in the listing part to show on the page the data of registered users, I have no idea how to do this part.
Here’s what I’ve done so far. JS and html.
function salvarConteudoStorage() {
var arraycadastro=[] if(JSON.parse(localStorage.getItem("data")) != null){ arraycadastro.push(JSON.parse(localStorage.getItem("data"))); }
if (typeof(Storage) !== " Undefined") {
var nome = document.getElementById("fnome").value;
var email = document.getElementById("femail").value;
var imagem = document.getElementById("imagem").value;
var repositorio = document.getElementById("repositorio").value;
var info = {nome, email, imagem, repositorio};
console.log(info);
arraycadastro.push(info);
var infoJson = JSON.stringify(arraycadastro);
localStorage.setItem("dados", infoJson);
} Else { window.Alert("Web Storage API not found"); } }
<body>
<div>
<form action="#">
<div >
<input type="text" id="fnome"/>
<label for="fnome">Nome</label>
</div>
<div >
<input type="text" id="femail"/>
<label for="femail">E-mail</label>
</div>
<div >
<input type="text" id="imagem"/>
<label for="imagem">URL da imagem</label>
</div>
<div >
<input type="text" id="repositorio"/>
<label for="repositorio">Github</label>
</div>
</form>
<button onclick="salvarConteudoStorage()">
Salvar
</button>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="armazenar.js"></script>
</body>
</html>
You helped a lot, man, thank you. But now I have another question: In the image part, when user put a url of an image in the text box, this image should load when displaying the data, and I saw that you used Jquery and I don’t know much about it, you have some idea of how to do it?
– DeJorg
Actually I didn’t use jquery, rs. This is a new standard of ES6 Avascript, template string. Instead of adding the td <td>${content.image}</td>, you can put a <img src={${content.image}}> remembering that the image content should be a URL to search the user. If you helped a PU in the answer to give me a strength, kkk. And you put the question as resolved, it helps me a lot to continue solving issues here
– Fernando Silva
I voted, but since I’m new, my vote is not counted. So bro, I tried to do what you said to the image and it’s giving this error "Failed to load Resource: net::ERR_FILE_NOT_FOUND". That damn picture is the only thing missing. Obg by help again =D.
– DeJorg