This question does belong to the Symfony2 userlist<https://groups.google.com/forum/?fromgroups=#!forum/symfony2>, not the Developers user list. Please post your answer there
-- Wouter Op woensdag 20 februari 2013 10:09:33 UTC+1 schreef Emre Avsar het volgende: > > I want to distinguish wheter a call to a route has been made directly via > browser or via ajax call. > > This is my ajax call, which does only a post to a rootMapping (defined in > my routing.yml) > > $("#ButtonId").click(function () { > $.ajax({ > url: "{{ path('rootMapping') }}", > type: "POST", > contentType:"application/json" > }); > }); > > The routing calls a method of the controller, for example > fooAction(Request $request) {...} > > I want to distinguish inside the fooAction wheter I need to return json > (for ajax calls, mobile-api) > or a rendering of a page (for the browser) > > I found something like this: > https://github.com/KnpLabs/KnpBundles/blob/master/src/Knp/Bundle/KnpBundlesBundle/Controller/DeveloperController.php#L35 > > But how can I set this request format? I tried it out with the official > documentation of Symfony2 to register a new MIME-Type ( > http://symfony.com/doc/2.0/cookbook/request/mime_type.html) but didn't > worked too.. (i tried it out with 'jsonp' and my ajax-call was > 'application/jsonp') > > > My other approach would be to check the contentType of the request for > 'application/json' and checking it with $format = > $this->getRequest()->getContentType(); > > But I think both of these approaches are not clean, they are in my point > of view hacks, aren't they? > > thanks and cheers > emre > > -- -- If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to symfony-devs@googlegroups.com To unsubscribe from this group, send email to symfony-devs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en --- You received this message because you are subscribed to the Google Groups "Symfony developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to symfony-devs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.