``In search of a solution: Resolving the Error Message "Dropzone already attached

Whenever I try to upload an image successfully, I need to execute the editDataImage() function in order to fetch the data stored on the server. However, I encounter an error when attempting to display the image data in the dropzone. Any assistance would be greatly appreciated!

Data Image Retrieval Function

            editDataImage(uuid){
                var app = this;
                app.$http({
                    url: app.api_url+'/gambarpengambilcontoh/'+uuid,
                    method: 'GET',
                }).then((response)=>{
                    var app = this;
                    app.imageList = response.data.data;
                    app.editGambar();
                });
            },

Dropzone Function

            editGambar(){
                var app = this;
                Dropzone.autoDiscover = false;
                $("#edit_image").dropzone({
                    url: app.api_url+'/gambarpengambilcontoh/tambah',
                    paramName: 'gambar_ambil_contoh',
                    headers: {
                        'Authorization': 'Bearer '+localStorage.getItem('authToken'),
                        'Accept': 'Application/json',
                    },
                    maxFiles: 10,
                    maxFilesize: 10,
                    addRemoveLinks: true,
                    init: function() {
                        var myDropzone = this;
                        if (app.imageList) {
                            for (var i = 0; i < app.imageList.length; i++) {
                                var mockFile = {
                                    name: app.imageList[i].gambar_ambil_contoh,
                                    status: Dropzone.ADDED,
                                    url: app.base_url+'/assets/gambarAmbil/'+app.imageList[i].gambar_ambil_contoh,
                                };
                                myDropzone.files.push(mockFile);
                                myDropzone.emit("addedfile", mockFile);
                                myDropzone.emit("thumbnail", mockFile, app.base_url+'/assets/gambarAmbil/'+app.imageList[i].gambar_ambil_contoh);
                                myDropzone.emit("processing", mockFile);
                                myDropzone.emit("success", mockFile);
                                myDropzone.emit("complete", mockFile);
                                $('.dz-image').last().find('img').attr({width: '120px', height: '120px'});
                            }
                        }

                        this.on("removedfile", function(file){
                            $.ajax({
                                headers: {
                                    'Authorization': 'Bearer '+localStorage.getItem('authToken'),
                                    'Accept': 'Application/json',
                                },
                                url: app.api_url+'/gambarpengambilcontoh/delete',
                                type: 'DELETE',
                                data: {'gambar_ambil_contoh': file.name}
                            })
                        });

                        this.on('sending', function(file, xhr, formData) {
                            formData.append('pengambil_contoh_id', app.formData.id);
                        });

                        this.on("success", function(file) {
                            app.editDataImage(app.formData.uuid); // callback to Data Image Retrieval Function
                        });

                    }
                })
            },

Error

Error: Dropzone already attached.

Apologies if my query seems a bit confusing!

Answer №1

Don't forget to move the line Dropzone.autoDiscover = false; outside of the editGambar() function

//Setting up Dropzone
Dropzone.autoDiscover = false;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming a request from Angular to PHP through formatting

I am currently working on creating an add function for my Angular application that communicates with my PHP back-end. I am attempting to send data to the server using a transformationRequest, but I am unsure about the correct format that matches the $_POST ...

Displaying Laravel's validation errors within the Ajax success event

When attempting an Ajax request and anticipating a failure, I find that the error response is unexpectedly being received within the success event instead of the fail event. I require Laravel's response to be directed to the Ajax fail event, as I int ...

The process of creating a project with Vue-cli has suddenly come

Whenever I attempt to create a project using vue-cli, it gets stuck at this point: >> vue init webpack test ? Project name test ? Project description (A Vue.js project) I can't even cancel it with ctl + c or any other command. Pressing enter ...

Guide on adding MySQL data into an object with [object HTMLCollection]

Hello and first of all, thank you for your assistance, my friends. I am facing an issue with inserting latitude and longitude routes from Google Maps, along with a text input field called "pathname" into my database. While the latitude and longitude are b ...

When users click on the tiles, they will act as interactive objects that will direct them to a different page within the Angular framework,

output Here is the code for my app component: <H1>AI API DEMOS</H1> <div> <ul> <li class="active"><a routerLink="/market">Market Size</a></li> <li role="presentation&qu ...

Exploring Amcharts using detailed JSON data

[{"SUM_PTS":{"datatype":"INTEGER","length":"8","value":"29903727","obfuscated":"false"},"SUM_TOTAL":{"datatype":"INTEGER","length":"10","value":"1644704985","obfuscated":"false"},"MID":{"datatype":"ALPHANUMERIC","length":"27","value":"Vendor 1","obfuscated ...

Emphasizing the date variable within a spreadsheet

Hey there! I'm struggling with the code below: <html> <head> <title>highlight date</title> <style> .row { background-color: Yellow; color:blue; } </style> <script type="text/javascript"> </script> &l ...

Guide on sending two values from a form using Ajax and the POST method

How can I send two values, A and B, from a form to check.php using Ajax with the POST method? In the code snippet below, I managed to send two input values to check.php and assign them to variables $A and $B. However, I want to accomplish this without ref ...

JavaScript application that features an audio player complete with a dynamic progress bar and customizable tags

Looking to create a custom audio player using HTML, CSS, and JS. The player should have basic functionality like a play button and progress bar. However, I want to allow users to add tags on the progress bar of the audio file, similar to how SoundCloud&apo ...

Issue with Material UI Autocomplete: onChange event not firing

When using Material UI's Autocomplete example, I am trying to choose an option using keyboard events: Navigate through options with the Up and Down arrow keys Press ENTER to select the desired option However, the onChange event is not being triggere ...

Enhance user interaction in Angular 13 by animating a selected element using just one animation block

I am currently working on a one-page website project to enhance my Angular skills, and I'm facing a challenge with animating multiple DOM elements using a single animation. Defining the animation for each element individually seems like a cumbersome a ...

Safari users encountering invalid dates generated by Moment Js library

Can anyone explain why I am seeing "invalid date" in Safari, but it works fine in other browsers? moment('01/01/2023 11:44:00.000 AM').tz(time_zone, true).format('hh:mm:ss:SS A z') chrome https://i.sstatic.net/PeFBp.png safari https ...

What is the most effective way to transmit a conditional operator via a TypeScript boolean field?

Currently, as part of my transition to typescript, I am working on incorporating a conditional operator into the table component provided by Ant Design. const paginationLogic = props.data.length <= 10 ? false : true return ( <> ...

Achieve the effect of background images fading in once the page loads, then disappearing when an accordion tab is

Currently on a project, I have implemented two background images that cross-fade on this website: www.alexarodulfo.com. I am interested in exploring the following possibilities: 1) Achieving a more subtle fade-in effect for the images, perhaps allowing th ...

Converting SQL database tables into MVC webpages using JavaScript

Currently, I am working on populating an MVC webpage by utilizing a Controller and a View using C#, HTML, and Javascript exclusively. It is crucial that I avoid using a model or PHP due to the existing format in use. Thus far, all the data has been succes ...

Place the button inside the form following another block element

Here is the HTML code I am working with: <div class="actions"> <input id="submit-car" name="commit" type="submit" value="Добавить объявление"> </div> and here is a fiddle example: http://jsfiddle.net/348U4/ In ...

Error: An unexpected symbol '<' was encountered after the build process in Vue.js

I just finished deploying a MEVN stack application to heroku. While everything is functioning properly locally, I am encountering a blank page and the following errors in the console post-deployment: Uncaught SyntaxError: Unexpected token '<' ...

Utilizing Material-UI components for a seamless navigation button experience

After reviewing the example on https://material-ui.com/guides/composition/#button, I have implemented a button in my main page: <BrowserRouter> <Box m={2}> <Button size="large" variant="cont ...

Using the chain method with Jquery's off() function

I can't figure out why my use of off() is not working properly. Is it trying to remove the class using removeClass() from document or #pager-next? $(document).off('click', '#pager-next').removeClass('disabled'); I want ...

Performing a function when text is clicked: Utilizing AngularJS

My goal is to trigger a specific controller method upon clicking on certain text. This function will then make remote calls to another server and handle the display of another div based on the response. Additionally, I need to pass parameters to this funct ...