Created
January 23, 2020 13:33
-
-
Save shreesubhendu/8bfb5f60e338c0cd5c1d8496c23622b3 to your computer and use it in GitHub Desktop.
Ajax post Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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