什么是最好的方式,一个控制器内,要知道如果请求是一个XMLHTTP一个或没有(ZF) [英] What is the best way, inside a controller, to know if the request is a XMLHTTP one or not (ZF)

查看:106
本文介绍了什么是最好的方式,一个控制器内,要知道如果请求是一个XMLHTTP一个或没有(ZF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动作不同的逻辑依赖,如果请求是一个AJAX一个或没有。
(对于AJAX登录,我不需要登录成功,这是不是在正常登录的情况下,例如后重定向)。
什么是最好的方式,检查标题为 X-要求,随着身旁:XMLHtt prequest
是否有标志的东西?

I have different logic in an action depends if the request is an AJAX one or not.
(For AJAX logins, I do not need to redirect after successful login, which is not the case in normal login, for example).
What is the best way, beside checking the headers for X-Requested-With: XMLHttpRequest
Is there a flag or something?

推荐答案

<一个href="http://framework.zend.com/apidoc/core/Zend%5FController/Request/Zend%5FController%5FRequest%5FHttp.html#isXmlHtt$p$pquest"相对=nofollow>这个方法通过检查这几乎设置(如果不是)所有主要的JS库,包括jQuery和YUI的。

This method works by checking for a header which is set by almost (if not) all of the major JS libraries, including jQuery and YUI.

$this->getRequest()->isXmlHttpRequest() //returns true if is XHR

由smack0007详述的方法,保证是准确的,但上述方法是正常,如果连接是由一个库,它设置首标总是制成。它可能是不适合公共API。

The method detailed by smack0007 is guaranteed to be accurate, but the method above is fine if the connection is always made by a library which sets the header. It is probably not suitable for a public API.

这篇关于什么是最好的方式,一个控制器内,要知道如果请求是一个XMLHTTP一个或没有(ZF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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