0

I need to initialize DropzoneJS with the dynamic url, which must be obtained via ajax call. How to do that without async: false? Result url will depend on files argument.

$('.class').dropzone({
    url: function(files) {
        var url;
        // ajax call here
        return url;
    },
});
lampslave
  • 1,431
  • 1
  • 15
  • 20

1 Answers1

0

Make the ajax call and then intialize plugin in the success of the ajax when you have the data:

Something like:

$.getJSON('path/to/server',function(response){
    $('.class').dropzone({
        url: function(files) {            
            return response.url;
        }
     });
}); 

I don't know this plugin or the data structure....adjust accordingly

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • I can't because `url` will be calculated according to `files`. – lampslave May 23 '16 at 01:45
  • Well without link to docs for plugin I can't help. remember there are 1000's of plugins out there and nobody knows all of them....and even when you do know them somewhat the api docs are critical – charlietfl May 23 '16 at 01:49
  • Also provide a more detailed explanation of exactly what is needed – charlietfl May 23 '16 at 01:50
  • For example I need different `url` for text files, media files, etc. – lampslave May 23 '16 at 10:20
  • That isn't a very detailed explanation as regarding ajax. Also why can't you use a single upload point and let the server sort out whatever issues you have? What exactly is this ajax inside the plugin url function needed for? – charlietfl May 23 '16 at 12:05
  • OK, maybe I can obtain `url` in another way... Please see [sending](http://www.dropzonejs.com/#event-sending) attr. Inside it I need to populate formData with all this [data](https://github.com/hovel/django-s3direct/blob/master/s3direct/views.py#L62-L74) which will always be different. – lampslave May 23 '16 at 12:24
  • See it for what? You are not being specific enough about anything to be able to help you. See [ask] and update question with enough details to work through whatever problem you have. I can't guess what you are trying to do or what constraints you have – charlietfl May 23 '16 at 12:46
  • I just need to return data from ajax call. Like [here](http://stackoverflow.com/a/16805366/2694042) but without `async: false`. Can I do that? – lampslave May 23 '16 at 12:53
  • Not simply because the plugin function won't wait for it and you should never use `async:false` and it is deprecated by browsers also – charlietfl May 23 '16 at 13:00