BrownieCoffee's avatar

Unexpected token < in JSON at position 0 | Summernote upload image and ajax

Hello there ,

I am creating my Ajax project so that it is saved as a draft.

I use summernote as wysiwyg and when I add an image I get a console error for formData.

Unexpected token < in JSON at position 0.

My project is saved but the image uploaded in summernote is not saved in database.

Can you help me to fix that please? Thank you in advance. See you.

my html

 <div class="box__content">
                <h2 class="box__heading box__heading--content">Contenu de votre projet</h2>
                <small>conseil: si vous souhaitez du texte après l'ajout de votre image, pensez à appuyer sur la touche "Entrer" pour revenir à la ligne.</small>
                <div class="box__content-field">
                    <textarea class="summernote" name="content" id="summernote_create"></textarea>
                </div>
                @error('content')
                <p class="help is-danger">{{ $message }}</p>
                @enderror
            </div>
            <div class="box__content">
                <input type="hidden" name="create_project_id" id="create_project_id">
                <div id="auto_save"></div>
            </div>

my ajax


        var project_content = $('#summernote_create').summernote("code");

        formData.append('content', project_content);


    $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
            method: 'POST',
            url: "/projets/",
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function (data) {

                console.log(data);

                if (data != '') {
                    $('#create_project_id').val(data);
                }
                $('#auto_save').text('saved');
                setInterval(function () {
                    $('#auto_save').text('');

                }, 2000);
            },
            error: function (data, textStatus, errorThrown) {
                console.log(data);

                console.error(textStatus + " " + errorThrown);
            }
0 likes
1 reply

Please or to participate in this conversation.