1
Good evening guys, I need some help with a JS vector...
When I type this way the same works ok, it displays all messages, but when I put the test variable in place it shows nothing:
var teste = document.getElementById('conversa').innerHTML;
return {
"messages":[
{"_id":"57","text":"oi mae","userId":"54","date":"2016-10-19T13:45:00.000Z"},{"_id":"54","text":"Oi filho","userId":"57","date":"2016-10-19T13:47:00.000Z"},{"_id":"54","text":"Leo","userId":"57","date":"2016-10-19T13:51:00.000Z"},{"_id":"54","text":"...","userId":"57","date":"2016-10-19T13:52:00.000Z"},{"_id":"54","text":"Ha","userId":"57","date":"2016-10-19T13:52:00.000Z"},{"_id":"54","text":"XD","userId":"57","date":"2016-10-19T13:56:00.000Z"},{"_id":"54","text":"...","userId":"57","date":"2016-10-19T13:56:00.000Z"},{"_id":"54","text":"Ahh","userId":"57","date":"2016-10-19T13:57:00.000Z"},{"_id":"54","text":"T","userId":"57","date":"2016-10-19T13:58:00.000Z"},{"_id":"54","text":"F","userId":"57","date":"2016-10-19T13:59:00.000Z"},{"_id":"54","text":"X","userId":"57","date":"2016-10-19T14:02:00.000Z"},{"_id":"54","text":"Kk","userId":"57","date":"2016-10-19T14:03:00.000Z"},{"_id":"54","text":"Xp","userId":"57","date":"2016-10-19T14:06:00.000Z"},{"_id":"54","text":"...","userId":"57","date":"2016-10-19T14:08:00.000Z"},{"_id":"57","text":"ok","userId":"54","date":"2016-10-19T14:08:00.000Z"},{"_id":"54","text":"Jdjjd","userId":"57","date":"2016-10-19T14:09:00.000Z"},{"_id":"54","text":"K","userId":"57","date":"2016-10-19T14:14:00.000Z"},{"_id":"57","text":"leo","userId":"54","date":"2016-10-19T14:14:00.000Z"},{"_id":"57","text":"ke","userId":"54","date":"2016-10-19T14:16:00.000Z"},{"_id":"54","text":"L","userId":"57","date":"2016-10-19T14:16:00.000Z"},{"_id":"57","text":"leo","userId":"54","date":"2016-10-20T16:40:00.000Z"},{"_id":"57","text":"leo","userId":"54","date":"2016-10-20T16:41:00.000Z"},
]
};
You could help me with a solution, I need the data to be dynamic within the "messages" vector... and this test variable is dynamic but when entering inside it shows nothing on the page.
Note: All this content
{"_id":"57","text":"oi mae","userId":"54","date":"2016-10-19T13:45:00.000Z"},{"_id":"54","text":"Oi filho","userId":"57","date":"2016-10-19T13:47:00.000Z"},{"_id":"54","text":"Leo","userId":"57","date":"2016-10-19T13:51:00.000Z"},{"_id":"54","text":"...","userId":"57","date":"2016-10-19T13:52:00.000Z"},{"_id":"54","text":"Ha","userId":"57","date":"2016-10-19T13:52:00.000Z"},{"_id":"54","text":"XD","userId":"57","date":"2016-10-19T13:56:00.000Z"},{"_id":"54","text":"...","userId":"57","date":"2016-10-19T13:56:00.000Z"},{"_id":"54","text":"Ahh","userId":"57","date":"2016-10-19T13:57:00.000Z"},{"_id":"54","text":"T","userId":"57","date":"2016-10-19T13:58:00.000Z"},{"_id":"54","text":"F","userId":"57","date":"2016-10-19T13:59:00.000Z"},{"_id":"54","text":"X","userId":"57","date":"2016-10-19T14:02:00.000Z"},{"_id":"54","text":"Kk","userId":"57","date":"2016-10-19T14:03:00.000Z"},{"_id":"54","text":"Xp","userId":"57","date":"2016-10-19T14:06:00.000Z"},{"_id":"54","text":"...","userId":"57","date":"2016-10-19T14:08:00.000Z"},{"_id":"57","text":"ok","userId":"54","date":"2016-10-19T14:08:00.000Z"},{"_id":"54","text":"Jdjjd","userId":"57","date":"2016-10-19T14:09:00.000Z"},{"_id":"54","text":"K","userId":"57","date":"2016-10-19T14:14:00.000Z"},{"_id":"57","text":"leo","userId":"54","date":"2016-10-19T14:14:00.000Z"},{"_id":"57","text":"ke","userId":"54","date":"2016-10-19T14:16:00.000Z"},{"_id":"54","text":"L","userId":"57","date":"2016-10-19T14:16:00.000Z"},{"_id":"57","text":"leo","userId":"54","date":"2016-10-20T16:40:00.000Z"},{"_id":"57","text":"leo","userId":"54","date":"2016-10-20T16:41:00.000Z"},
Is within the variable teste
.
return JSON.parse(teste)
;– bfavaretto
in the console gave this error when placing the above code: Syntax Error: Unexpected token u in JSON at position 0
– Leonardo Da Costa Rodrigues
Ah now I understood octaciojb, I opened this topic to pick up the contents of div, flowed cool has already been solved... but now the problem is different as described above.
– Leonardo Da Costa Rodrigues
OK, unchecked. Good luck on the solution.
– Chefe Druida
Help me out, guys =(
– Leonardo Da Costa Rodrigues
It’s still listed as a duplicate question but it’s not
– Leonardo Da Costa Rodrigues
Possible duplicate of Ajax results only on console?
– Thiago Luiz Domacoski