我正在使用 jquery-file-upload 上传文件。
文件上传完成后,我想重定向到上传文件的编辑路径。
我正在使用 javascript 提交文件:
return data.submit();
文件上传完成后,如何重定向到edit_document_path,我尝试了以下代码:
$('#fileupload')
.bind('fileuploadstop', function (e, data) {
window.location.href = "#{edit_document_path(@document)}";
})
有没有办法可以存储或返回上传文档的 ID(甚至更好的是 @document 本身),以便我可以通过 js 重定向?
编辑
我的 js 直接在 html.haml 文件中
%script(type="text/javascript")
$('#new_document').fileupload({
dataType: 'json',
add: function (e, data) {
jqXHR = data.submit()
},
done: function (e, data) {
window.location = json.url
},
progress: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('.bar').css('width', progress + '%');
}
});
这是我的控制器:
def upload
@document = Document.new(params[:document])
respond_to do |format|
format.json { render json: { url: edit_document_path(@document) } }
end
end
但是,由于页面没有重定向,JSON 响应似乎不起作用,我做错了什么?
谢谢