我试图转到上一页,但它不工作,不知何故给我"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (Connection: mysql, SQL: insert into 'students' ('name', 'email', 'contact', 'course', 'updated_at','created_at') values (?, ?, ?, ?, 2023-07-12 08:59:56, 2023-07-12 08:59:56))"
这个错误
create.blade
<div class="div2">
<form method="post" name="form" class="create_form" action="{{ route('students.store') }}" enctype="multipart/form-data">
@csrf
Name <input type="text" name="name" id="name"><br><br>
Email <input type="text" name="email" id="email"><br><br>
Contact <input type="text" name="contact" id="contact"><br><br>
Course <input type="text" name="course" id="course"><br><br>
<button type="submit" class="save_create">Save</button>
<button type="submit" class="back_create" formaction="{{ route('students.index') }}">Back</button>
</form>
</div>
字符串
AJAX 提交和返回按钮代码块
$(document).on('submit', '.create_form', function(event) {
event.preventDefault();
var data = $(this).serialize();
$.ajax({
url: "{{ route('students.store') }}",
data: data,
type: "POST",
dataType: "json",
success: function(response) {
window.location.href = ("{{ route('students.index') }}");
},
error: function(error) {
console.log("Errors :", error);
}
});
});
// Back button clicked on create page
$(".back_create").on("click", function(event) {
event.preventDefault();
$.ajax({
type: "GET",
url: "{{ route('students.index') }}",
success: function(response) {
window.location.href = ("{{ route('students.index') }}");
}
});
});
型
路由是完全控制器:
Route::resource('/students',StudentController::class);
我试着把url使用
$(this).attr('formaction ')
但保存按钮也不起作用。
1条答案
按热度按时间qgzx9mmu1#
你该换衣服了
字符串
至
型
由于按钮的类型是
submit
将提交表单,而不是把这个块型
向外
$(document).on('submit')...