Tuesday, September 29, 2020

Laravel ajax query param


<input type="hidden" name="_token" value="{{csrf_token()}}">

or use only CSRF blade directive

@csrf



$(function(){

	 $('#form').submit(function(e){
	 	e.preventDefault();

	 	var _url = $(this).attr('action'),
	 		_type = 'POST',
	 		_data = $(this).serialize();

	 	$.ajax({
		    url: _url,
		    type: _type,
		    data: _data,
		    success: function (data) { 
		        // do something after success
		    }
		});

	 })
 

}); 

No comments:

Post a Comment