I'm trying to make my comment submit form work without refresh, and append the data into a div to show the comment. Currently the submit form works, it's inserted into the database so the data is passed to the controller, but it's not shown on console.log and the append.
JS
$("#newsCommentForm").submit(function(e){
e.preventDefault();
$.ajax({
method: 'POST',
url: '/store',
data: $(this).serialize(),
success:function(data){
console.log( $( this ).serialize() );
$('#test').append(data);
},
error: function( e ) {
console.log(e);
}
});
});
Controller
protected function storeNewsComment(Request $request)
{
Comment::create([
'user_id' => Auth::user()->id,
'blog_id' => $request->input('blog_id'),
'body' => $request->input('body'),
]);
}
I made a test div in the view
<div id="test">
</div>
storeNewsComment()your action? if so, why is it protected? Also, it is not returning anything