0

I want to upload a profile image of a user to the server and i'm stuck at ajax upload of image.

All my form data are not posting to database including the image name and the file is not uploading to the server.

<script>
    $(document).ready(function()  {
        $('#sacrificeForm').submit(function(event){
            event.preventDefault();
            $.ajax({
                url:'{{ route('sacrifice.store') }}',
                method:"POST",
                data : $('#sacrificeForm').serialize(),
                success:function(data){
                    const variables = ['sacrifice', 'fileSacrifice'];
                    variables.forEach(variable => {
                        if(data[variable] === null) data[variable] = '';
                    });
                    let html = '' +
                        '<tr>'+
                        '<td class="fw-normal">'+data.id+'</td>'+
                        '<td class="fw-normal">'+data.sacrifice+'</td>'+
                        '<td>'+
                        '<form method="post" id="sacrifice-destroy">'+
                        '@csrf'+
                        '@method('DELETE')'+
                        '<div class="btn-group">'+
                        '<a data-id="'+data.id+'" class="btn btn-info btn-sm" id="sacrificeEdit" data-bs-toggle="modal" data-bs-target="#sacrificeModal">ویرایش</a>'+
                        '<button data-id="'+data.id+'" type="button" class="btn btn-danger btn-sm" id="sacrificeDestroy">حذف</button>'+
                        '</div>'+
                        '</form>'+
                        '</td>'+
                        '</tr>';
                    $('#sacrificesTable').append(html);
                },
            });
        });
    });
</script>

0 Answers0