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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With