php 为什么内容标题“application/javascript”会导致 500 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/81896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:24:47  来源:igfitidea点击:

Why is the Content Header 'application/javascript' causing a 500 Error?

phpiis-7mime-types

提问by Voidstate

I have a script that works fine on my test server (using IIS6). The script processes an ajax request and sends a response with the following line:

我有一个在我的测试服务器上运行良好的脚本(使用 IIS6)。该脚本处理一个 ajax 请求并使用以下行发送响应:

header( 'application/javascript' );

But on my live server, this line crashes the page and causes a 500 error.

但是在我的实时服务器上,这一行会使页面崩溃并导致 500 错误。

Do I need to allow PHP to send different MIME types in IIS7? If so, how do I do this? I can't find any way on the interface.

我是否需要允许 PHP 在 IIS7 中发送不同的 MIME 类型?如果是这样,我该怎么做?我在界面上找不到任何方法。

回答by Sietse

The header is incorrect, try this instead:

标题不正确,试试这个:

header('Content-Type: application/javascript');

回答by Voidstate

take a look at http://en.wikipedia.org/wiki/Mime_type

看看http://en.wikipedia.org/wiki/Mime_type

There it says you should use application/javascript instead of text/javascript.

它说你应该使用 application/javascript 而不是 text/javascript。