jeudi 28 novembre 2019

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. How can I submit the form without refreshing the page?

Blade

 <form action="#" id="add-productForm" method="POST" role="form" enctype="multipart/form-data">
            

               <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=""  ></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 = "";
    e.preventDefault();
    $.ajax({
        type: "post",
        url: url,
        data: $(".add-productForm").serialize(),

        success: function(store) {

        },
        error: function() {
        }
    });
});
</script>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire