Skip to content

Instantly share code, notes, and snippets.

@Luizgpp
Last active September 20, 2016 23:16
Show Gist options
  • Save Luizgpp/e3f31947d05a12c5c7f536151a1d86b7 to your computer and use it in GitHub Desktop.
Save Luizgpp/e3f31947d05a12c5c7f536151a1d86b7 to your computer and use it in GitHub Desktop.
// create post
$('form#form-post').on("submit", function(e){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'POST',
dataType: 'json',
url : '{{ route('posts.store') }}',
data: { data: $(this).serialize() },
beforeSend: function(data){
console.log(data);
},
success: function(data) {
console.log(data);
window.location.href('{{ route('posts.index') }}');
},
error: function(xhr, textStatus, thrownError) {
console.log(thrownError);
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment