1
Good afternoon guys, I can bring a result in the log, but in the div is not passed on, follows my source:
Index.php
var teste;
$.ajax({
url: 'conversa.php',
type: 'GET',
success: function(res) {
$("#conversa").html(res);
teste = $("#conversa").html(res);
console.log(document.getElementById("conversa"));
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
php conversation.
<?php
include '../../abreConexao.php';
session_start();
$query = "SELECT * FROM chat WHERE meu_id='" . $_SESSION['id-cadastro'] . "' AND parceiro_id='" . $_SESSION['paquera_chat'] . "' OR meu_id='" . $_SESSION['paquera_chat'] . "' AND parceiro_id='" . $_SESSION['id-cadastro'] . "' ORDER BY data_hora ASC";
$result = mysql_query($query);
while ($fetch = mysql_fetch_array($result)) {
$variavel .= '{"_id":"' . $fetch['parceiro_id'] . '","text":"' . $fetch['mensagem'] . '","userId":"' . $fetch['meu_id'] . '","date":"' . $fetch['data_hora'] . '"},';
}
echo $variavel;
?>
I just really wanted to take the select of the.php conversation and display it in index via ajax. I’ll be waiting, guys, thank you.
--Solved
$.ajax({
url: 'conversa.php',
type: 'POST',
success: function(res){
$("#conversa").empty();
$("#conversa").append(res);
teste = document.getElementById('conversa').innerHTML;
console.log(document.getElementById("conversa"));
}
});
What exactly do you want to display within the div? The answer is coming from an object with various information!
– JuniorNunes
I really want to show off.
– Leonardo Da Costa Rodrigues
So, but for you to do this, I think you’ll have to make a loop to add each element in the div
– JuniorNunes
exactly as it is on the console
– Leonardo Da Costa Rodrigues
because it looks echo on my php page looks like this:{"_id":"57","text":"hi mom","userid":"54","date":"2016-10-19T13:45:00.000Z"},{"_id":"54","text":"Hi son","userid":"57","date":"2016-10-19T13:47:00.000Z"},
– Leonardo Da Costa Rodrigues
Try the following: $("#conversation"). html(JSON.stringify(res)); see if the whole object appears inside the div
– JuniorNunes
Try using . append(res) instead of . html(res)
– Hugo Leonardo
so I used append, but when I give Object Object Alert
– Leonardo Da Costa Rodrigues
$("#conversation"). html(JSON.stringify(res)) also appeared nothing
– Leonardo Da Costa Rodrigues
I did one more test here you guys & #Xa;$("#conversation"). append(res); it worked Muitoooo thanks.
– Leonardo Da Costa Rodrigues
Put the result as a response and, after two days, mark it as the right answer.
– William Aparecido Brandino