Система комментирования в прямом эфире с Laravel и AjaxJquery

Программирование на jquery
Anonymous
Система комментирования в прямом эфире с Laravel и Ajax

Сообщение Anonymous »

Я хочу внедрить живую систему комментариев для каждого поста моего проекта < /p>
Это моя точка зрения < /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){

}
});

});
});

comment submitted and saved in database totally fine but i get this, and whole view goes away
Изображение

i want to achieve something like this

Спасибо за вашу помощь

Подробнее здесь: https://stackoverflow.com/questions/797 ... l-and-ajax

Вернуться в «Jquery»