Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  44] [ 5]  / answers: 1 / hits: 34418  / 9 Years ago, fri, november 20, 2015, 12:00:00

I am quite new at JavaScript and this is driving me crazy.



I want to use Dropzone.js so I downloaded the file dropzone.js from here and included it in my view like this:



<script src=<?php echo JS_DIRECTORY; ?>/dropzone.js></script>


Then I created the form like that:



<form action=http://localhost/project/uploadTest/upload class=dropzone>
</form>


And it works fine. It points it to php function and I handle upload on server site.



The problem is when I want to access the dropzone object in JS to configure it.
When I do



// myAwesomeDropzone is the camelized version of the HTML element's ID
Dropzone.options.myAwesomeDropzone = {
paramName: file, // The name that will be used to transfer the file
maxFilesize: 2, // MB
accept: function(file, done) {
if (file.name == justinbieber.jpg) {
done(Naha, you don't.);
}
else { done(); }
}
};


I get




Uncaught ReferenceError: Dropzone is not defined




Any help will be appreciated, thanks


More From » jquery

 Answers
20

Your code might run too soon. Wrap it in:



window.onload = function() {
// access Dropzone here
};


or, better (runs sooner than above code):



document.addEventListener(DOMContentLoaded, function() {
// access Dropzone here
});


or, if you use jQuery:



$(function() {
// access Dropzone here
});

[#64325] Wednesday, November 18, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;