Это моя точка зрения < /p>
Код: Выделить всё
@extends('layouts.main')
@section('content')
{{ $post->title }}
// there is nothing wrong about showing post data
{{ $post->body }}
@csrf
submit
< /code>
Это мой контроллер < /p>
public function addComment(Request $request){
$comment = new Comment();
$comment->postId = $request->postId;
$comment->name = $request->name;
$comment->comment = $request->comment;
$comment->save();
return response()->json(['success' => 'thanks for your comment']);
}
< /code>
И это мой код Ajax < /p>
$(document).ready(function(){
$("#company_form_btn").click(function(e){
e.preventDefault();
var url = $(this).attr("action");
let formData = new FormData(this);
$.ajax({
type:'POST',
url: url,
data: formData,
contentType: false,
dataType:'json',
cache: false,
processData: false,
success:function(response){
alert(response.success)
},
error: function(response){
}
});
});
});

i want to achieve something like this
Спасибо за вашу помощь
Подробнее здесь: https://stackoverflow.com/questions/797 ... l-and-ajax
Мобильная версия