-1

I have a page that fetches an ajax response. That response

  1. includes another ajax response
  2. the last response has a dropzone which is initialised with the following

$(document).ready(function() {
    $("#uploadme").dropzone({
        paramName: 'photos',
        url: 'upload.php',
        dictDefaultMessage: "drop here",
        clickable: true,
        enqueueForUpload: true,
        maxFilesize: 1,
        uploadMultiple: false,
        addRemoveLinks: true
    });
});

That works well the first time.

The second response (2.) reloads itself when posting in a form. When this happens, I get this error in the console

Uncaught TypeError: $(...).dropzone is not a function

I guess (and I'm purely guessing now) that dropzone is called upon to soon, but how do I solve this?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Thomas
  • 87
  • 7
  • How is the dropzone library included on the page? – mark_c Oct 01 '17 at 12:08
  • It´s included in the header at the first page, below Jquery. – Thomas Oct 01 '17 at 15:06
  • here: http://historiska.xn--regrund-80a.se/?tomt=F.46:3 – Thomas Oct 01 '17 at 15:09
  • `$(document).ready(function($) {` Most likely you have multiple versions of jquery. adding `$` to the ready callback gives you a `$` that won't be overwritten by the additional version of jquery. you should definitely avoid having multiple versions of jquery. – Kevin B Oct 03 '17 at 21:20

1 Answers1

1

I might have find a solution myself.

First of all, I moved the code outside $(document).ajaxComplete(function())

Second, using clues found on DropzoneJS: How to get PHP response after upload success? , I rewrote the code to

   new Dropzone("#uploadme", { 
               maxFilesize: 2, // MB
               dictDefaultMessage: "Dra bilder hit om du vill inkludera dom i din kommentar",
            url: 'upload.php',
            init: function() {
                this.on("success", function(file, responseText) {
                    console.log(responseText);
                });
            }
        });

I'm not quite sure why it worked, but it might help someone else.

Thomas
  • 87
  • 7