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 Comments

  • Cynthia

    Hey folks, I love IE too.

    Microsoft land, please fix this MIME bug with twitter!

  • Mo

    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?

  • Eric Bartels

    Hi Mo,

    what mime-types did you use? Have you “watched” your response-headers with a http-proxy or live-headers?