Problem with JS / PHP [closed]

0

Good afternoon guys,

I'm trying to make a chat to my intranet and the problem is as follows, my code in JS is not capturing the echo return from PHP, so the function does not delete the text that the person writes in the chat after the enter , could you help me?

Follow 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 noticed that submit.php is working:

Thank you!

    
asked by anonymous 03.05.2018 / 21:19

2 answers

1

Your error is writing, the callback should be success and not sucess!

    
03.05.2018 / 21:27
1

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

    
03.05.2018 / 21:29