Symfony $ request-> isXmlHttpRequest()问题 [英] Symfony $request->isXmlHttpRequest() issue
问题描述
我需要检查请求是否为ajax. $request->isXmlHttpRequest()
可以正常工作,但是,如果在执行过程中某处存在重定向,则此方法将返回false.在这种情况下,我还能如何检查请求是否为ajax?
p.s. ajax由jQuery启动
I need to check if the request is ajax. $request->isXmlHttpRequest()
works fine, however if there is a redirect somewhere during the execution, this method will return false. How else can I check if request is ajax in this case?
p.s. ajax is initiated by jQuery
推荐答案
如果您没有重定向到项目中的另一个应用程序或另一个外部uri,则在第一个请求上isXmlHttpRequest为true时,只需使用forward即可.
If you arent redirecting to a different application in your project or another external uri just use forward instead if isXmlHttpRequest is true on the first request.
该方法检查X-Requested-with
标头的值,并且在某些浏览器实现中,标头(或所有原始标头)已从重定向的请求中删除/覆盖(FF为名称一).
Well that method checks against the value of the X-Requested-with
header and in some browser implementations that header (or all original headers) are dropped/overwritten from the redirected request (FF to name one).
作为解决方法,您可以在请求本身中使用变量.您也许可以使用现有的sf_format
基础结构,但是由于不确定其内部工作方式,因此不确定是否可以使用.
As a workaround you could use a variable in the request itself. You might be able to use the existing sf_format
infrastructure, but im not sure if that would work because im not familiar with how it works internally.
这篇关于Symfony $ request-> isXmlHttpRequest()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!