<p dir="auto">When a request is made through AJAX Symfony correctly knows that the request is an XMLHttpRequest. This can be retrieved from the isXmlHttpRequest method of the Request class. However, this doesn't set the _format parameter in the request to the correct value. For example, making an AJAX request with JQuery.ajax sends the content-type <strong>application/json</strong> which isn't then used to set the response format. This means that for example when an exception is thrown and returned as response it will always be in HTML format except when a route has the _format parameter explicitly set. I don't find anything about the fact that this behaviour is intended. I resolved by setting manually that parameter if I detect that the request is an XMLHttpRequest. However, I really think that this is a bug because Symfony should always use the content-type if detected to generate the appropriate response</p>
<p dir="auto">The symfony default _format which is used to determine the right template should be aware of the HTTP Accept header(<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" rel="nofollow">http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html</a>)</p>
<p dir="auto">This shouldn't effect the default behavior like it is right now for websites, but if you're building an (REST[FUL]) API this would be a really great improvement.</p>
<p dir="auto">As far as I discovered it now, the format is determined here: [...]/symfony/src/Symfony/Component/HttpFoundation/Request.php:833</p>
<p dir="auto">What do you think?</p>