javascript - JS : XMLHttpRequest only works on specific file extensions?

标签 javascript iis xmlhttprequest

我正在从事 WebGL 项目。我正在使用 XMLHttpRequest 加载着色器(文本文件)、JSON 模型(文本文件)。当我对具有异常扩展名(例如 .vs 或 .json)的文件使用 XMLHttpRequest 时,我将返回 404 状态。如果我将该文件重命名为以 .txt 或 .html 结尾,它将正常加载(状态 200)。是否了解限制成功检索哪些文件的因素?

抱歉,如果这是一个简单的问题,我是网络开发的新手。我一直无法通过谷歌找到答案。我正在使用 IIS 在本地为站点提供服务。

最佳答案

我猜这与 XMLHttpRequest 无关。当您尝试通过 Web 浏览器中的地址栏或类似 cURL 的方式直接访问这些资源时会发生什么?

IIS 上的默认安全配置很可能会阻止提供“无法识别的”文件。您可能需要为它们注册 MIME 类型,或禁用安全配置。

有关这方面的一些详细信息,请访问 http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/44aa974e-ad27-4800-adfb-13c4ae39a602.mspx?mfr=true。 .特别注意:

You can also configure IIS to serve undefined file types by adding a wildcard character (*) MIME type. Do not use wildcard MIME-types on production servers. Doing so can result in IIS serving unrecognized files and displaying sensitive information to users. Wildcard MIME-types are intended for testing purposes or in scenarios where Internet Server API (ISAPI) filters have been developed specifically to handle these wild card scenarios, for example, a custom authentication ISAPI.

如果您需要额外帮助,http://serverfault.com可能是询问有关配置 IIS 的详细信息的更好的地方。

关于javascript - JS : XMLHttpRequest only works on specific file extensions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8547560/

相关文章:

visual-studio-2010 - 附加到 Visual Studio Express 2013 for Web 中的进程

通过 IIS 运行 MVC 应用程序时 CSS 样式不起作用

ajax - 如何使针对 Google Apps Script ContentService 的 XHR/ajax 请求起作用?

javascript - 检测父元素边缘的 jQuery 最佳方法

javascript - 如何根据数据路径查找元素并更改其中的类

rest - 解析服务器 SSL IIS

javascript - js从html标签中获取值

javascript - 如何使用 jQuery 异步上传文件?

javascript - 在页面加载时随机定位 div

javascript - 使用 jQuery 访问按钮的替代文本