To solve the issue, I modified common.inc on line 2482 from:

drupal_set_header('Content-Type: text/javascript; charset=utf-8');

to

drupal_set_header('Content-Type: text/html; charset=utf-8');

Apparently, IE doesn't know what to do with javascript, but it does know what to do with html.

Comments

damien tournoud’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

It's unclear what you are trying to achieve here. text/javascript is (one of) the correct MIME type for javascript files.

rfay’s picture

@balancemedia_de, you need to give a better and more complete description of your issue.

rfay’s picture

Component: ajax system » javascript
swood’s picture

I'm actually having the same problem with IE and this "fixes" the issue. What's happening is when using AHAH on a page, IE is attempting to download the JSON instead of simply executing it. You first get a popup saying that IE is unable to download the file and needs your permission. If you tell it to download file security warning asking if you want to save or find a program to open it. The name will be related to the form and the media type will be 'Unknown File Type'. IE seems to be unable to make use of the text/javascript in the JSON request as it doesn't understand it. Changing to text/html makes it work. I've seen this same behavior with the "poll' module on my website. Not sure why others aren't seeing the same problem.

rfay’s picture

Status: Postponed (maintainer needs more info) » Active

@swood, can you give a step-by-step on how to recreate this in core? Much appreciated.

swood’s picture

Sure, it's actually very easy in my environment.

Using poll and IE 8.
1. node/add/poll
2. select 'Add another choice'

IE will popup dialog box with security warning. image attached

If I replace the drupal_json with text/html instead of the current text/javascript it will work fine.

Same problem with any of my ahah code on button type elements. Dropdowns using ahah to change view don't have the same issue.

swood’s picture

StatusFileSize
new30.88 KB

Forgot to add attachment

heine’s picture

Could not yet reproduce.

A possible related issue: #341588: json output must use correct mime-type

cha0s’s picture

I couldn't reproduce either, using IETester on XP running under VBox.

swood’s picture

If I attempt to change the content-type to application/json, it doens't fix IE and FF will request to download the file. FF works with either text/html or text/javascript, but IE ignores all. I've seen references to others having the same type of problem but it doesn't appear to be universal. I get it all the time from my application, but obviously others aren't from theirs. I wonder what the difference is?

heine’s picture

Some questions:

- Does this happen with Garland?
- What version of jQuery does your site use (aka do you use jQuery Update)?
- What security zone is the website in?
- Is this a 'normal' IE installation (not a multi-version install)?

heine’s picture

Do you have a site exhibiting this phenomenon that we could investigate?

swood’s picture

- It does happen with Garland
- I'm using 1.3.2 of jquery. I'm actually using a modified jquery 1.12.2.3 but changed it back to see if behavior changed. It doesn't
- Happens in both intranet and internet zones. I've got users complaining about it on the production site. I'm able to reproduce on my test server
- It is a normal installation. As I said, users are reporting the issue.

heine’s picture

Drupal 6.x comes with jQuery 1.2.6. Other versions of jQuery are not supported and likely to break due to #479368: D7: Create RFC compliant HTML safe JSON.

Can you reproduce this on a fresh installation of core?

EmmyS’s picture

We're on core 6.2 and using jQuery 1.2.6 with the jQuery Updater, and we're having the same problem - IE8 is trying to download json files instead of reading them. This can be reproduced 100% of the time.

I tried the original poster's fix of changing drupal_set_header in the drupal_json function to text/html didn't work - it just opened the json file in the browser instead of downloading it.

Note that we're not using the Poll module; this is happening using custom code that calls drupal_json().

norio’s picture

Like @EmmyS, I'm also experiencing this issue and the OP's fix just displays the JSON instead of executing it.

acbramley’s picture

I'm having the problem on Core 6.2. I've tried changing the line in includes/commons.inc +2537 from

drupal_set_header('Content-Type: text/javascript; charset=utf-8');

to

drupal_set_header('Content-Type: text/html;');

And it fixed it in all browsers. This seems to be a pretty dodgy fix, but seems to work with all the testing I've done.

Opinions?

acbramley’s picture

StatusFileSize
new559 bytes

Here's a patch for it.

heine’s picture

For those who can repro 100% of the time; please provide a link so we can take a peak.

Please note that we only support jQuery that comes with core.

generalredneck’s picture

StatusFileSize
new624 bytes

Reroll of #18 from the root directory of the checkout.

Working on seeing if I can reproduce this with vanilla Drupal. So far...

Drupal 6.22 works
Drupal 6.22 with Jquery update 6.x-2.0-alpha1 and packaged jquery works
Drupal 6.22 with Jquery update 6.x-2.0-alpha1 and jquery 1.7 works.

Things to try...
Older versions of jquery update
Check for server specific header differences.

What generates this is I can get my work's server to do that, but I cannot release a site, however the tests have been done on my personal server.

I'll keep you all up to date.

hefox’s picture

I'm getting reports of this issue also, but only on an ahah callback that uploads a file.

So I checked what filefield was doing:

  // For some reason, file uploads don't like drupal_json() with its manual
  // setting of the text/javascript HTTP header. So use this one instead.
  print drupal_to_js(array('status' => TRUE, 'data' => $output));

So they experienced the same thing essentially. I did a helluvalot of googling and wasn't able to find a good solution outside of not adding the text/Javascript application/json header :/

dealancer’s picture

Patch from comment #17 worked well for me, though the sollution proposed in #341588: json output must use correct mime-type does not.

dealancer’s picture

Version: 6.16 » 6.x-dev
Status: Active » Needs review
StatusFileSize
new455 bytes

Here is re rolled patch that could be applied to the recent 6.x-dev.

druser01’s picture

Issue summary: View changes

I am having the same issue for Drupal 7.14 as well, but I donot see any existing issue queue for this so continuing the same, can someone please respond if its still an issue or if there is a fix for D7.14?
Thanks

stephenrobinson’s picture

I have had to hack ajax_deliver in includes/ajax.inc

      // drupal_add_http_header('Content-Type', 'application/json; charset=utf-8'); // removed
      if( (strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE 9.0')>-1 || strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE 8.0')>-1 || strpos($_SERVER["HTTP_USER_AGENT"], 'WOW64')>-1 ) && (strpos($_SERVER["REQUEST_URI"], '/file/ajax')===0||strpos($_SERVER["REQUEST_URI"], '/system/ajax')===0) ){
        drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
      }
      else{
        drupal_add_http_header('Content-Type', 'application/json; charset=utf-8');
      }
stephenrobinson’s picture

I have had to alter my patches as some IE's are reporting "trident" in headers:

/includes/common.inc

function drupal_json_output($var = NULL) {
  // We are returning JSON, so tell the browser.
  // drupal_add_http_header('Content-Type', 'application/json'); // removed
  if( 
       strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE 8.0')>-1 
    || strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE 9.0')>-1 
    || strpos($_SERVER["HTTP_USER_AGENT"], 'WOW64')>-1 
    || strpos($_SERVER["HTTP_USER_AGENT"], 'Trident')>-1 
  ){  
    drupal_add_http_header('Content-Type', 'application/html');
  }
  else{
    drupal_add_http_header('Content-Type', 'application/json'); 
  }
  ......

/includes/ajax.inc

function ajax_deliver($page_callback_result) {
  ........................
      // drupal_add_http_header('Content-Type', 'application/json; charset=utf-8'); // removed
      if( 
        (
             strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE 9.0')>-1 
          || strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE 8.0')>-1 
          || strpos($_SERVER["HTTP_USER_AGENT"], 'WOW64')>-1 
          || strpos($_SERVER["HTTP_USER_AGENT"], 'Trident')>-1
        ) 
        && 
        (
             strpos($_SERVER["REQUEST_URI"], '/file/ajax')===0 
          || strpos($_SERVER["REQUEST_URI"], '/system/ajax')===0 
        )   
      ){
        drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
      }
      else{
        drupal_add_http_header('Content-Type', 'application/json; charset=utf-8');
      }
PatchRanger’s picture

Version: 6.x-dev » 7.x-dev
Category: Support request » Bug report
StatusFileSize
new1.9 KB

Regarding #24, #25, #26: I am having the same issue with Drupal 7.41. As #24 mentioned, I've failed to find the corresponding issue for Drupal 7. And looks like this one is correct place as it is opened against Drupal 6 while in fact it should be raised to the highest major version possible and Drupal 8 replaced the corresponding code with Symfony\Component\HttpFoundation\JsonResponse (see https://www.drupal.org/node/1665684) - so I am bumping this issue to Drupal 7.
Attaching a patch to review. It is just an implementation of what was mentioned in #25, #26. I've removed the piece with strpos'ing $_SERVER["REQUEST_URI"] - I didn't understand why it is necessary.
Please review.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.