轨道3 - 如何实施一个Ajax请求重定向响应 [英] rails 3 - how to implement redirect response with an ajax request

查看:163
本文介绍了轨道3 - 如何实施一个Ajax请求重定向响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想请求一个页面一个简单的场景。请求格式是阿贾克斯。如果在该请求的控制器/动作逻辑一些错误,我想重定向到一个错误页面。问题是,一个重定向是不是一个JavaScript响应类型,所以我不知道它是否会奏效。

I have a simple scenario where I want to request a page. The request format is ajax. If there is some error in the controller/action logic for that request, I want to redirect to an error page. The issue is that a redirect is not a javascript response type, so I am not sure whether it will work.

如果没有错误,那么我想在页面通过适当的javascript响应类型进行更新。

If there are no errors, then I want the page to be updated via the appropriate javascript response type.

什么是最好的做法来实现重定向​​给予响应该请求的格式是AJAX?

What is best practice to achieve redirect responses given that the request format is ajax?

一个快速code样品将是非常美联社preciated。

A quick code sample would be much appreciated.

感谢。

推荐答案

这个博客帖子开导我什么,我认为是正确的方式来做到这一点,如果你的Ajax响应是阿贾克斯;至少,在不显眼的JavaScript范例。从根本上,Ajax调用总是返回一个标准的JSON的包,它可以被解析的信息有效载荷或重定向URL。

This blog post enlightened me on what I think is the right way to do this, if your ajax response is ajax; at least, in the unobtrusive javascript paradigm. In essense, the ajax call always returns a standard json package, which can be parsed for information payload or a redirect url.

这篇关于轨道3 - 如何实施一个Ajax请求重定向响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆