I'm trying to add product to the database with Ajax without refreshing the page and send the data to the database but I get an error Uncaught ReferenceError: $ is not defined
on console.
(我正在尝试使用Ajax将产品添加到数据库而不刷新页面并将数据发送到数据库,但是出现错误Uncaught ReferenceError: $ is not defined
在控制台上Uncaught ReferenceError: $ is not defined
。)
How can I submit the form without refreshing the page?(如何在不刷新页面的情况下提交表单?)
Blade
(刀)
<form action="#" id="add-productForm" method="POST" role="form" enctype="multipart/form-data">
{{csrf_field()}}
<label for="pro_name">Name</label>
<input type="text" class="form-control" name="pro_name" id="pro_name" placeholder="Enter product name">
<label for="category_id">Choose Category</label>
<select name="category_name" id="category_name">
<option value=""> --Select Category -- </option>
@foreach ($categoryname_array as
$data)
<option value="{{ $data->name }}" >{{$data->name}}</option>
@endforeach
</select>
<label for="photos">Choose 5 Images</label>
<input "multiple="multiple" name="photos[]" type="file">
<button type="button" class="btn btn-primary">Submit</button>
</form>
Route
(路线)
Route::post('seller/product', 'ProductController@store')->name('product.store');
Ajax
(阿贾克斯)
<script>
$(document).on("click", "#save", function(e) {
let url = "{{route('product.store')}}";
e.preventDefault();
$.ajax({
type: "post",
url: url,
data: $(".add-productForm").serialize(),
success: function(store) {
},
error: function() {
}
});
});
</script>
ask by joh translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…