Description
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 application/json 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