Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the JSON reponse in drop zone ajax call

Currently working on a dropzone functionality with the spring MVC framework.

This is the method in the controller class ( I'm using internal view resolver)

 @RequestMapping(value = "/save", method = RequestMethod.POST, produces = "application/json")
        @ResponseBody
        public String save(MultipartHttpServletRequest request,
                HttpServletResponse response, Model map) {
//The logic for adding file to db and creation of json object here
.....
.....

userDataJSON = strWriter.toString();
return userDataJSON;

}

Here is my javascript for the dropzone upload

Dropzone.options.myAwesomeDropzone = {          

        maxFilesize : 2,
        addRemoveLinks : true,          
        uploadMultiple : true,          
        init : function() {     
            this.on("addedfile", function(file) {                               
                $.ajax({
                method  : 'get'             
                }).done(function( data, textStatus, xhr ) {                 
                    alert(data);
                    //Expecting the json objec here

                });
            });  
        }
};

Here i'm not getting the json reponse, from the controller.

Please let me know if you have any solutions for me. Thanks in advance.

like image 856
PCA Avatar asked Oct 27 '13 13:10

PCA


1 Answers

I believe by default, dropzonejs is doing the ajax request to your file.

    $("#uploader").dropzone({ 
        url: "/upload.php",
        maxFilesize: 3,
        init: function() {
            this.on("success", function(file, response) {
                var obj = jQuery.parseJSON(response)
                console.log(obj);
            })
        }
    });

the url param is what is getting hit via the ajax call, and response (in the console.log) is what is coming back from /upload.php

like image 88
Matt Avatar answered Sep 28 '22 18:09

Matt