如何检查的要求是阿贾克斯的TurboGears [英] how to check if request is ajax in turbogears

查看:178
本文介绍了如何检查的要求是阿贾克斯的TurboGears的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何去检查,如果一个请求是在的TurboGears控制器方法Ajax请求?此外,是否有可能返回一个部分很像栏杆或symfony中,如果请求是一个Ajax请求。我知道了JSON的装饰,但我需要一种方法来返回一个Mako的模板的部分(因为我需要对数据进行格式化并不愿意做这一切在Javascript)。例如,如果我想返回的格式列表新闻列表的第二页,我不希望返回整个页面(而不仅仅是格式化列表)。

How do I go about checking if a request is an ajax request in a controller method in Turbogears? Further, is it possible to return a 'partial' much like in rails or symfony if the request is an ajax request. I know about the json decorator but I need a way to return a partial of a mako template (because I need to format the data and don't want to to do it all in Javascript). For example if I want to return the formatted list for page two of a list of news stories, I do not want to return the entire page (but rather just the formatted list).

感谢

推荐答案

的jQuery,YUI,原型,Dojo和MooTools的所有设置页眉 X-要求,通过:XMLHtt prequest 。你应该可以检查该头。

jQuery, YUI, Prototype, Dojo, and MooTools all set the header X-Requested-With: XMLHttpRequest. You should be able to check for that header.

这篇关于如何检查的要求是阿贾克斯的TurboGears的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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