Last active
November 28, 2017 06:36
-
-
Save cyberfly/7d9258985e169c6015ec to your computer and use it in GitHub Desktop.
laravel form ajax with jquery
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
//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