Wednesday, March 8, 2017

Upload image using Ajax and laravel

im working in my laravel projecto, and im using ajax, but im having some issues in one of the fields, input file, ajax is not sending or detecting the file input field, it sends data from other inptus fields but not the file here is my code above:

$('#savePersonalData').click(function(event) {
            event.preventDefault();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },

                method: 'PUT',
                url: '/',
                data: $( '#personalDataForm' ).serialize()


            }).done(function(response){
                //console.log(JSON.stringify(response));
                console.log(response);
            }).fail(function(response) {
                console.log(response.responseJSON);
            });

        });

html:

some inputs fields (text, options,etc)...
 <div style="text-align: right;" class="col-md-4 ">
                                <div id="image-preview">
                                    <label for="image-upload" id="image-label">Foto Perfil</label>
                                    <input type="file" name="avatar" id="image-upload" />
                                </div>

                            </div>



via Pedro

Advertisement