Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

javascript - What problems may using the MIME type application/json cause?

I am working on a web service the needs to return JSON data. I read that I should use application/json but am not sure what problems this may cause?

For example, will older browsers support it? (IE6+, FF, Opera, etc.)

Or is it possible that users behind corporate firewalls/proxy servers block the mime type application/json?

What, if any, problems have you had following this advice?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let's consider IE. Say you have a hidden iFrame which you use to request a file download. For example

<iframe src="getFile?id=123">

Now, the server may send a JSON-encoded error message like

{
    error: 'File 123 does not exist',
    retryLater: false
}

If that error message is sent as application/json, a download dialog will appear, because the JSON text is mistaken for the actual file.

On the other hand, a MIME type of text/plain will cause the message to be rendered in the iFrame, and you can extract it, and transform it into a fancy pop-up or something using JScript.


(Edit)

Real-world example: EXTJS Fileupload - Problem with IE8 security bar


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...