Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

javascript - ReferenceError Laravel和Javascript(ReferenceError Laravel and Javascript)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Common problem, before script you need to load your jQuery library.

(常见问题,在脚本之前,您需要加载jQuery库。)

<script src="/your_path/jquery.plugin.js"></script>
<script src="/your_path/jquery.min.js"></script>

More: https://javarevisited.blogspot.com/2016/04/3-ways-to-solve-jquery-uncaught-reference-error-is-not-defined.html

(更多: https : //javarevisited.blogspot.com/2016/04/3-ways-to-solve-jquery-uncaught-reference-error-is-not-defined.html)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...