Unfortunately in tg1 the JSON stuff is done in the expose decorator function, and it's not done in a way that's easily visible to the wrapped function (your controller).
In TG2 this will be changed so that the base controller class does the content negotiation, and the expose decorator registers information in a location that can be accessed from the base controller, but also from your controller methods. This question makes me thing we should also expose a way to ask for the expected "results" of the content negotiation process in the controller method (this, actually should be pretty easy.) Some of this stuff is still being worked out, ase we decide where the expose decorator, and it's friends will live in Pylons/tg2 land (should they go up into Pylons, or stay in TurboGears land?) --Mark On 9/25/07, iain duncan <[EMAIL PROTECTED]> wrote: > > On Wed, 2007-26-09 at 01:02 +0200, Christopher Arndt wrote: > > iain duncan schrieb: > > > I've read the docs on returning json, and can see that if I use > > > 'allow_json=True' that the controller will detect that we want json > > > based on either tg_format="json" or headers with accept javascript. > > > > > > What I can't figure out is how I can detect *within* controller code > > > what kind of return we'll be doing. > > > > By convention, most JavaScript libraries will add a special HTTP header > > "X-Requested-With: XMLHttpRequest" to all AJAX request. > > > > See the is_xhr function in the new Genshi tutorial for a way to detect this: > > > > http://genshi.edgewall.org/wiki/GenshiTutorial#AjaxifiedCommenting > > > > > > HTH, Chris > > Thanks Chris, that does help at least get me on track. I'm hoping to > find out from controller code though. I figure there must be a single > flag or mechanism that is set if the controllers know when to return > json. I just need to know how to directly access that from within a > controller method, but don't see that mentioned in the json docs. > > If someone knows, I'd be happy to add an example of what I'm doing to > the json docs. > > Iain > > > > > > -- Mark Ramm-Christensen email: mark at compoundthinking dot com blog: www.compoundthinking.com/blog --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

