I am using iframe for uploading files in rails 3.2, after submitting form using iframe how to redirect my page in "ajax" call
我使用iframe在rails 3.2中上传文件,在使用iframe“ajax”调用中提交如何重定向页面的表单之后
if @user.save
format.html { redirect_to users_path }
format.json { render json: @user, status: :created, location: @user }
format.js { render :layout => false }
end
I am tried using,
我试着用,
format.html { render js: "window.location.pathname = #{users_path.to_json}" }
3 个解决方案
#1
6
This works for me:
这工作对我来说:
format.js {render js: "window.location = '#{users_path}';"}
Don't forget to quote '
the url inside the js string, because in the code you pasted in your question you seem to have forgot them
不要忘记引用“js字符串内部的url,因为在您粘贴的问题中的代码中,您似乎忘记了它们”
Also use users_path
and not users_path.to_json
还要使用users_path而不是users_path.to_json。
#2
1
It can be
它可以
if @user.save
format.html { redirect_to users_path }
format.json { render json: @user, status: :created, location: @user }
format.js { render js: "window.location = '#{users_url}';" }
end
so when it will ajax request it will automatically execute format.js
and it will render
所以当ajax请求时,它会自动执行格式。它会渲染。
#3
1
You can simply use redirect_to(users_path) in your action in controller
您可以在控制器的操作中使用redirect_to(users_path)
#1
6
This works for me:
这工作对我来说:
format.js {render js: "window.location = '#{users_path}';"}
Don't forget to quote '
the url inside the js string, because in the code you pasted in your question you seem to have forgot them
不要忘记引用“js字符串内部的url,因为在您粘贴的问题中的代码中,您似乎忘记了它们”
Also use users_path
and not users_path.to_json
还要使用users_path而不是users_path.to_json。
#2
1
It can be
它可以
if @user.save
format.html { redirect_to users_path }
format.json { render json: @user, status: :created, location: @user }
format.js { render js: "window.location = '#{users_url}';" }
end
so when it will ajax request it will automatically execute format.js
and it will render
所以当ajax请求时,它会自动执行格式。它会渲染。
#3
1
You can simply use redirect_to(users_path) in your action in controller
您可以在控制器的操作中使用redirect_to(users_path)