PCA*_*PCA 4 ajax jquery dropzone.js
目前正在使用spring MVC框架开发dropzone功能.
这是控制器类中的方法(我正在使用内部视图解析器)
@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;
}
Run Code Online (Sandbox Code Playgroud)
这是我的dropzone上传的javascript
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
});
});
}
};
Run Code Online (Sandbox Code Playgroud)
在这里,我没有从控制器获得json响应.
如果您有任何解决方案,请告诉我.提前致谢.
Mat*_*att 12
我相信默认情况下,dropzonejs正在对您的文件执行ajax请求.
$("#uploader").dropzone({
url: "/upload.php",
maxFilesize: 3,
init: function() {
this.on("success", function(file, response) {
var obj = jQuery.parseJSON(response)
console.log(obj);
})
}
});
Run Code Online (Sandbox Code Playgroud)
url param是通过ajax调用得到的,响应(在console.log中)是从/upload.php返回的内容