How to use Ajax in any form submission?
BY Best Interview Question ON 27 Apr 2019
Example
<script type="text/javascript">
$(document).ready(function() {
$("FORMIDORCLASS").submit(function(e){
// FORMIDORCLASS will your your form CLASS ot ID
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
// you have to pass in between tag
}
})
var formData = $("FORMIDORCLASS").serialize();
$.ajax({
type: "POST",
url: "",
data : formData,
success: function( response ) {
// Write here your sucees message
}, error: function(response) {
// Write here your error message
},
});
return false;
});
});
</script>