Problems with Internet Explorer and application/json

My current project based on Symfony and YUI was developed using Firefox (and its great plugin Firebug) and Safari. It made heavy use of JSON. My Symfony action looked like

public function executeSomething ()
{
  $this->getResponse ()->setHttpHeader ('Content-Type', 'application/json');
  // ... Do something
  return $this->renderText ($myJsonCode);
}

Nothing spectacular. This code works with Opera, Firefox and Safari. The application/json is the official Mime-Type for JSON.

Save as …

If you call this action via your JavaScript-code with the famous Internet Explorer (IE7 in this case) the “Save as …” – dialog appears and IE wants me to save a file! What?!

Workaround

The reason behind this is that Internet Explorer cannot associate the application/json Mime-Type to an application installed on the client-side.
To get around this simply use text/javascript as Content-Type inside Symfony.

public function executeSomething ()
{
  $this->getResponse ()->setHttpHeader ('Content-Type', 'text/javascript');
  // ... Do something
  return $this->renderText ($myJsonCode);
}

Conclusion

I love IE!

3 thoughts on “Problems with Internet Explorer and application/json”

  1. Hello,
    I tried doing everything to get the JSON to work with IE 7 but some how its giving me an error. Its working on FF, Safari..etc but IE nope.. any idea?

Comments are closed.