如何检查请求是否是turbogears中的ajax

时间:2022-05-25 07:18:20

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).

如何在Turbogears的控制器方法中检查请求是否是ajax请求?此外,如果请求是ajax请求,是否可以像rails或symfony一样返回'partial'。我知道json装饰器,但我需要一种方法来返回mako模板的一部分(因为我需要格式化数据而不想在Javascript中完成所有操作)。例如,如果我想返回新闻故事列表第二页的格式化列表,我不想返回整个页面(而只是返回格式化列表)。

Thanks

谢谢

1 个解决方案

#1


1  

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

jQuery,YUI,Prototype,Dojo和MooTools都设置了标头X-Requested-With:XMLHttpRequest。您应该能够检查该标题。

#1


1  

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

jQuery,YUI,Prototype,Dojo和MooTools都设置了标头X-Requested-With:XMLHttpRequest。您应该能够检查该标题。