Skip to content

Instantly share code, notes, and snippets.

@shreesubhendu
Created January 23, 2020 13:33
Show Gist options
  • Save shreesubhendu/8bfb5f60e338c0cd5c1d8496c23622b3 to your computer and use it in GitHub Desktop.
Save shreesubhendu/8bfb5f60e338c0cd5c1d8496c23622b3 to your computer and use it in GitHub Desktop.
Ajax post Laravel
<script>
$(".add").click(function () {
var data = $('#form').serializeArray();
data.push({name: '_token', value: $('input[name=_token]').val()});
$.ajax({
type: 'POST',
url: 'ajaxmovies',
data: data,
success: function (data) {
toastr.success('Successfully added Module!', 'Success Alert', {timeOut: 5000});
$('#add_form').modal('hide');
location.reload();
},
error: function (data) {
var errors = data.responseJSON;
var items = "<ul>";
$.each(errors.errors, function (key, val) {
$("#" + key + "-error").html(val);
items += '<li>' + val + '</li>';
});
items += '</ul>';
toastr.error("Error: Validating data. ", 'Alert!', {timeOut: 5000});
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment