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.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | d7-952220-json_header_fix.patch | 1.9 KB | PatchRanger |
| #23 | drupal-952220-json-header-23.patch | 455 bytes | dealancer |
| #20 | drupal-json-header-fix-2.patch | 624 bytes | generalredneck |
| #18 | drupal-json-header-fix-1.patch | 559 bytes | acbramley |
| #7 | error.jpg | 30.88 KB | swood |
Comments
Comment #1
damien tournoud commentedIt's unclear what you are trying to achieve here.
text/javascriptis (one of) the correct MIME type for javascript files.Comment #2
rfay@balancemedia_de, you need to give a better and more complete description of your issue.
Comment #3
rfayComment #4
swood commentedI'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.
Comment #5
rfay@swood, can you give a step-by-step on how to recreate this in core? Much appreciated.
Comment #6
swood commentedSure, 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.
Comment #7
swood commentedForgot to add attachment
Comment #8
heine commentedCould not yet reproduce.
A possible related issue: #341588: json output must use correct mime-type
Comment #9
cha0s commentedI couldn't reproduce either, using IETester on XP running under VBox.
Comment #10
swood commentedIf 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?
Comment #11
heine commentedSome 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)?
Comment #12
heine commentedDo you have a site exhibiting this phenomenon that we could investigate?
Comment #13
swood commented- 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.
Comment #14
heine commentedDrupal 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?
Comment #15
EmmyS commentedWe'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().
Comment #16
norio commentedLike @EmmyS, I'm also experiencing this issue and the OP's fix just displays the JSON instead of executing it.
Comment #17
acbramley commentedI'm having the problem on Core 6.2. I've tried changing the line in includes/commons.inc +2537 from
to
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?
Comment #18
acbramley commentedHere's a patch for it.
Comment #19
heine commentedFor 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.
Comment #20
generalredneckReroll 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.
Comment #21
hefox commentedI'm getting reports of this issue also, but only on an ahah callback that uploads a file.
So I checked what filefield was doing:
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 :/
Comment #22
dealancer commentedPatch from comment #17 worked well for me, though the sollution proposed in #341588: json output must use correct mime-type does not.
Comment #23
dealancer commentedHere is re rolled patch that could be applied to the recent 6.x-dev.
Comment #24
druser01 commentedI 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
Comment #25
stephenrobinson commentedI have had to hack ajax_deliver in includes/ajax.inc
Comment #26
stephenrobinson commentedI have had to alter my patches as some IE's are reporting "trident" in headers:
/includes/common.inc
/includes/ajax.inc
Comment #27
PatchRanger commentedRegarding #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.