JSFiddle - React, Tailwind, and code Playground
by mohit001
HTML
<html>
<head>
<title>Form submit without refresh</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<form method="post" action="" id="loginform">
<input name="username" type="text" id="username" ><br>
<input name="password" type="password" id="password" ><br>
<input name="email" type="text" id="email"><br>
<button type="submit" id="btn" class="btn-login left" >Submit</button>
</form>
</html>
JavaScript
$(document).ready(function () {
$('.btn-login left').click(function (e) {
e.preventDefault();
var username = $('#username').val();
var password = $('#password').val();
var email = $('#email').val();
$.ajax
({
type: "POST",
url: "success.php",
data: { "username": username, "password": password, "email": email },
success: function (data) {
$('.result').html(data);
$('#contactform')[0].reset();
}
});
});
});