i have form that works with ajax method to send, and i need to refresh the page after submition then show success of form inside a div. my question is : is there a way to refresh main page once and then show form success? here is my snippet :
$(document).ready(function() {
$(document).on('click', '.MyForm button[type=submit]', function(e) {
e.preventDefault() // To make sure the form is not submitted
var $frm = $(this).closest('.MyForm');
console.log($frm.serialize());
$.ajax(
$frm.attr('action'),
{
method: $frm.attr('method'),
data: $frm.serialize(),
success: function(data) { $(".error").html(data)}
}
);
});
});
.error{width:200px; height:50px;border:1px solid blue;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<form class="MyForm" method="post">
<input type="text" placeholder="name" value="Aynaz" name="a1" />
<select name="Avg">
<option value="1">1</option>
<option value="2">2</option>
</select>
<button type="submit">Submit</button>
<div class="error">Show form success here after page reload</div>
</form>