Empty and Append return no value

Asked

Viewed 63 times

0

I’m having the problem that my Empty(). append(); does not return any php values in div and I can’t insert anything into it, even within html itself. It’s like she’s been blacking out, but for a second I see that the content typed in HTML is there, but it’s gone again. Can someone help me?

HTML

 <!DOCTYPE html>
<html>
<head>
    <title>Sala <?=$nick?></title>
    <meta charset="utf-8">
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>

<body style="background-color: #1C1C1C;" onload="carregaMensagem()">

<div class="container">
    <div id="mensagens">
    </div>

    <form onsubmit="enviar(); return false" method="post" action="">
        <input type="text" id="mensagem" placeholder="Digite sua mensagem" class="form-control">
        <input type="submit" style="display:none;">
    </form>

</div>

</body>
</html>

PHP

<?php 
    require_once("inc/config.php"); //conexão com banco

    if (isset($_SESSION['nickname'])) {
        $sql = msql_query("SELECT * FROM mensagem");
        if (mysql_num_rows($sql) > 0) {
            while ($ln = mysql_fetch_assoc($sql)) {
                echo '<p>Seja Bem vindo'.$_SESSION['nickname'].'</p>';
                echo '<p>Digita /sair deslogar do chat</p>';
                $nick = strip_tags($ln['nickname']);
                $mensagem = htmlspecialchars($ln['mensagem']);
                echo "<p>".$nick.":".$mensagem."</p>";
            }
        } else {
            echo '<p>Seja Bem vindo'.$_SESSION['nickname'].'</p>';
            echo '<p>Digita /sair deslogar do chat</p>';
            echo "Nenhuma mensagem até o momento.";
        }

    } else {
        require_once("inc/nick.php"); // pede pra definir nick
    }
?>

JAVASCRIPT/JQUERY

function carregaMensagem() {

    var url = "verMensagem.php";
    jQuery.get(url, function(data){
        setInterval(intervaloMsg(data), 3000);

    }); 
}

function intervaloMsg(dados){
    $("#mensagens").empty().append(dados);
    //$("#mensagens").html(dados);

}

function enviar() {
    var url = "enviarMensagem.php";
    var mensagem = $("#mensagem").val();

    var enviando = $.post(url,{mensagem:mensagem});
    console.log(mesangem);
}

Thank you all for your attention and I apologize if there are any mistakes.

  • You can forget the sending() part; I just gave a continuation in the code even that part not working, but even without sending it(); nothing appears. He should return me on screen echo '<p>Be Welcome'. $_SESSION['nickname']. '</p>'; echo '<p>Type /logout chat</p>'; echo "No message so far." ; But nothing returns to me.

  • Yes, later I realized that your problem was the initial warning not to be displayed. But I posted an answer, see if that’s it

1 answer

0


I think the mistake is on that line:

$sql = msql_query("SELECT * FROM mensagem");

The right thing would be

$sql = mysql_query("SELECT * FROM mensagem");

There is also an error in javascript

console.log(mesangem);

The right thing would be

console.log(mensagem);
  • Gosh I blew it, thank you very much friend. I need to change my glasses kkk

  • Rs. Was that right? It worked?

  • It worked, but now I’m stuck elsewhere. I can’t get inside the bank kkk

  • Mark that answer as correct and open another question with your new problem so I can try to help.

Browser other questions tagged

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