i have a form like this :
Move out SendData
from document.ready
function SendData() {
$.ajax({
url: "save.php",
type: "post",
data: "msg="+$('#chat_in').val(),
dataType: 'json',
success: function(){
alert("Sent");
},
error:function(){
alert("failure");
}
});
}
$(document).ready(function () {
$('#chat_in').keypress(function(e) {
if(e.which == 13) {
alert('You pressed enter!');
SendData();
}
});
$('#bt').click(function() {
SendData();
});
});