Skip to content

Instantly share code, notes, and snippets.

@cyberfly
Last active November 28, 2017 06:36
Show Gist options
  • Save cyberfly/7d9258985e169c6015ec to your computer and use it in GitHub Desktop.
Save cyberfly/7d9258985e169c6015ec to your computer and use it in GitHub Desktop.
laravel form ajax with jquery
//at view blade, must put data-remote
{!! Form::open(array('data-remote','url' => 'notices/'.$notice->id, 'method' => 'PATCH')) !!}
//js
$(function() {
var submitAjaxRequest = function(e){
var form = $(this);
var method = form.find('inputp[name="_method"]').val() || 'POST';
$.ajax({
url: form.prop('action'),
type: method,
data: form.serialize(),
success: function()
{
alert('success');
}
});
e.preventDefault();
};
$('form[data-remote]').on('submit', submitAjaxRequest);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment