1

I'm trying to use the Jodit editor and wish to use the image uploading capabilities to specify a folder and path of where to upload it to using a PHP script.

I'm trying to put in some console.log statements to check my values, but when I select an image, I receive this error in the console which I don't know how to fix.

enter image description here

The code I've used in the page is:

<script>

var editor = new Jodit('#editor_Jodit',{
    enableDragAndDropFileToEditor: true,
    uploader: {
        url: 'connector/upload.php',
        format: 'json',
        pathVariableName: 'path',
        filesVariableName: 'images',
        prepareData: function (data) {
            return data;
        },
        isSuccess: function (resp) {
            return !resp.error;
        },
        getMsg: function (resp) {
            return resp.msg.join !== undefined ? resp.msg.join(' ') : resp.msg;
        },
        process: function (resp) {
            return {
                files: resp[this.options.uploader.filesVariableName] || [],
                path: resp.path,
                baseurl: resp.baseurl,
                error: resp.error,
                msg: resp.msg
            };
        },
        error: function (e) {
            this.events.fire('errorPopap', [e.getMessage(), 'error', 4000]);
        },
        defaultHandlerSuccess: function (data, resp) {
            var i, field = this.options.uploader.filesVariableName;
            if (data[field] && data[field].length) {
                for (i = 0; i < data[field].length; i += 1) {
                    this.selection.insertImage(data.baseurl + data[field][i]);
                }
            }
        },
        defaultHandlerError: function (resp) {
            this.events.fire('errorPopap', [this.options.uploader.getMsg(resp)]);
        }
    }
});
editor.value = '<p>start</p>';
</script>

2 Answers 2

0

Try to remove the following line:

filesVariableName: 'images' 
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 6, 2021 at 19:02
0

Replace with a function

filesVariableName: function (r) {
                    return 'images'
                },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.