0
jQuery('body').on('keyup', '.mesg', function(e){
if (e.which == 13) {
var texto = $(this).innerHTML();
var id = '$id:5';
$.ajax({
type: 'POST',
url: 'msgamigos.php',
data: {mensagem: texto, de: id},
success: function(retorno){
if(retorno == 'ok'){
$('.mesg').innerHTML('');
}else{
alert('Ocorreu um erro ao enviar a mensagem');
}
}
});
}else{alert('Ocorreu um erro ao receber a mensagem'); }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=\"mesg\" id=\"mesg\" tabindex=\"0\" contentEditable=\"true\" data-text=\"Publish Your news\" spellcheck=\"true\" aria-multiline=\"true\" style=\"color:grey;background:white;width:100%;height:19.5px;vertical-align:middle;border-left:1px solid grey;\"></div></div></div></div>';
<div class=\"mesg""id=\"mesg\" tabindex=\"0\" contentEditable=\"true\" data-text=\"Publish Your news\" spellcheck=\"true\" aria-multiline=\"true\" style=\"color:grey;background:white;width:100%;height:19.5px;vertical-align:middle;border-left:1px solid grey;\"></div></div></div></div>';
Try using this : var key = e.keycode || e.charCode; Instead of e.which;
– Bruno
still not working
– Pedro Ferreira
but at least when I click on any key, this error no longer appears
– Pedro Ferreira