i have no knowledge about websocket for chat i want to use php ajax for form submit for chat i want to sumbit form dynamically without reload but it gets reload ( which i dont want ). i have created a chat in which php sends information to xml as and displays all xml information, and when user submits the form below
<form action="action.php" method="post" id="formpost">
<input type="text" id="input" value="php echo">
<input type="submit" value="send">
</form>
it reloads to display this php
<div class="msg"><?php print $message->getName() ." : " . $chat->message . ""; ?></div>
Additional info : when i remove the chat $chat->message . no msgs display because the php loop only name shows in <div class="msg"> above
i have tried this to submit form dynamically by javascript but when i click the button a alert comes with my own html <html><body>..</html>, and when i reload the page manually msg shows
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("#formpost").on('submit', function(event){
event.preventDefault();
var form = $(this);
var url = form.attr('action');
$.ajax({
type: "POST",
url: "club.php",
data: form.serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
});
</script>
$( document ).ready(?