I am trying to submit data to the db without refreshing the page using jquery and php
But I guess there is something I get wrong in my code , its works nicely if I do not apply Jquery :
Bellow is my code am using .
<!---Insert into database -->
<script type="text/javascript">
$(document).ready(function () {
$('.chatbutton').click(function () {
$.ajax({
type: 'post',
url: "insertchatmessages.php",
success: function () {}
});
});
});
</script>
<!---Insert into database ends here -->
</head>
<body>
<table class="chattable" id="chattable" border="0">
<tr><td><div id="load_tweets">
</div></td></tr>
<form id ="chatform" action="?" method="post"></td></tr>
<tr><td><input class ="chattext" type ="text" name="message"></td></tr>
<tr><td><input class="chatbutton" class="chatbutton" type="submit" value="send" name ="submit">
</div>
</table>
HTML (this is derived from your code but modified to work in jsfiddle):
jQuery:
Working example: http://jsfiddle.net/darshanags/6vxMs/6/
Notes: I have made slight modifications to your code to make it work on jsfiddle, you will have to change it back to make it work in your setup.