0
Personal I am trying to get the data via json besides to list I want to save in the browser, more I am not getting if someone can help me follow the code
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags must come first in the head; any other head content must come after these tags -->
<title>Tutorial Web App</title>
<!-- Bootstrap -->
<link href="bootstrap.css" rel="stylesheet">
</head>
<body>
<h1>Listar objetos</h1>
<ul class="list-group">
</ul>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap.js"></script>
<script>
$(function(){
var objetos = JSON.parse(window.localStorage.getItem('objetos'))
//window.localStorage.removeItem('objetos')
$.each(objetos, function(index, item){
$('.list-group').append('<li class="list-group-item">'+ item.id + ' ' + item.nome +'</li>')
})
$.get('https://coarinet.com/teste.json')
.done(function(resposta){
// a varivel resposta (pode ser qualquer nome) recebera os dados retornados pela requisicao
// aqui voce faz o que quiser com os dados
// exemplo de laco de repeticao
$.each(resposta, function(indice, item){
// faz algo a cada interaca
$('.list-group').append('<li class="list-group-item">'+ item.id.nome +'</li>')
window.localStorage.setItem('objetos', JSON.stringify(resposta))
})
})
})
</script>
</body>
</html>
The
window.localStorage.setItem
no need is inside theeach
. Error appears when pressingF12
?– Valdeir Psr
No one appears
– Hemerson Prestes
I’m actually getting an idea of another code as I don’t know much I’m trying to adapt this ai rsrss
– Hemerson Prestes
JSON is incorrect in https://coarinet.com/teste.json and before the
$.each(resposta
use theresposta = JSON.parse(resposta)
– Valdeir Psr
See of the json is right now ?
– Hemerson Prestes
Taking a leather so far nothing rssr
– Hemerson Prestes