Problem with JS/PHP

Asked

Viewed 46 times

0

Good afternoon, everyone,

I am trying to chat to my intranet and the problem is this, my JS code is not capturing the return via PHP echo, so the function does not erase the text that the person writes in the chat after enter, could help me?

Follows the codes:

Submit.php

<?php
if(isset($_POST['mensagem'])){
    include("../conectaBanco.php");

    $mensagem = strip_tags(trim(filter_input(INPUT_POST, 'mensagem', FILTER_SANITIZE_STRING)));
    $de = (int)$_POST['de'];
    $para = (int)$_POST['para'];
    $tempo = time();

    if($mensagem != ''){
        $insert = "INSERT INTO mensagens (id_de, id_para, mensagem, time, lido) VALUES ('$de','$para','$mensagem','$tempo','0')";
        if($res = mysqli_query($conn, $insert)){
            echo 'ok';
        }else{
            echo 'no';
        }
    }
}
?>

Function.js

    jQuery('body').on('keyup', '.msg', function(e){
    if(e.which == 13){
        var texto = jQuery(this).val();
        var id = jQuery(this).attr('id');
        var split = id.split(':');
        var para = Number(split[1]);

        jQuery.ajax({
            type: 'POST',
            url: './sys/submit.php',
            data: {mensagem:texto, de: userOnline, para: para},
            sucess: function(retorno){
                if(retorno == 'ok'){
                    jQuery('.msg').val('');
                }else{
                    alert('Ocorreu um erro ao enviar a mensagem :(');
                }
            },
            error: function(){
                alert('Ocorreu um erro ao enviar a mensagem :(');
            }
        });
    }
});

Through Firebug I realized that Submit.php is working:

inserir a descrição da imagem aqui

Thank you!

2 answers

1


Your error is written, the callback must be Success and not succeed!

  • That’s right, thank you!!!

1

In your ajax request, you have the callback sucess that does not exist, right would be success

Browser other questions tagged

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