[英]How to customize server response with jquery file upload from json
I working on file upload feature on Ruby on Rails using this jQuery file upload , I used this example to accomplish the task. 我使用此jQuery文件上载功能在Ruby on Rails上进行文件上载功能,我使用此示例完成了该任务。 the problem here is that as appeared in the example the response in create action with a json object so the uploaded content can be listed
这里的问题是,如示例中所示,使用json对象创建操作时的响应,因此可以列出上载的内容
render json: [@upload.to_jq_upload].to_json, status: :created, location: @upload
but I want to response with a different action after the image is uploded like format.js or .html, so How can I do this? 但是我想在图像升格后像format.js或.html一样以不同的动作响应,那么我该怎么做?
The JS where the JSON is rendered should be changed from $.getJSON
to $.getScript
呈现JSON的JS应该从
$.getJSON
更改为$.getScript
Then, in your controller, drop the render :json
you have and put something like: 然后,在您的控制器中,删除您拥有的
render :json
并放置类似以下内容:
respond_to do |format|
format.html {}
format.js {}
end
You should have a view that matches the corresponded format (my_view.js.erb or my_view.html.erb). 您应该具有与相应格式(my_view.js.erb或my_view.html.erb)匹配的视图。 Then put the code you want there.
然后将您想要的代码放在此处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.