Ajax works well for pre-existing forms. But if I add a new form using it and submit it, then I get to the method page.
Added a new form, filled in the field and clicked Submit: http://joxi.ru/DmBOW4KUzep962
I get to the method page, instead of displaying the result in the console: http://joxi.ru/EA4P710TOekbOA
After reloading the page, everything works well.
What could be the matter, tell me please.
Front:
$('.add-answer-form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: `/admin/courses/48/lessons/96/answerAdd`,
data: $(this).serialize(),
success: function (data) {
console.log('!!!!!', data);
}
});
});
Back:
public function answerAdd(Request $request, Course $course, Lesson $lesson, Test $test, Answer $answer){
$this->answer->fill($request->all())->save();
return response ()->json ($this);
}