![](/img/trans.png)
[英]Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking i
[英]python 2 web server local host error. The server responded with a non-JavaScript MIME type of “text/plain”
(第一次)我使用python -m SimpleHTTPServer 8000
python 2.7.15为我的简单JavaScript游戏生成了一个Web服务器(仍在学习中),但似乎有一些错误,这使得我的HTML文件的画布无法显示。
JavaScript可以在我的GitHub页面上正常工作,但不会在本地Web服务器上显示。 https://jcloh98.github.io/jsgame/simplegame2.html
所有代码均与网站完全相同。 那就是我使用的所有代码。
这是控制台日志中显示的错误。
无法加载模块脚本:服务器以非JavaScript MIME类型“ text / plain”响应。 根据HTML规范对模块脚本强制执行严格的MIME类型检查。
https://jcloh98.github.io/jsgame/simplegame2.html
预计将在画布底部显示一个带有水色桨的黑色画布,例如https://jcloh98.github.io/jsgame/simplegame2.html
代替使用python -m SimpleHTTPServer 8000
,创建一个名为“ localhost.py”的.py文件,然后在网页的同一目录中运行该.py文件。
localhost.py强制将扩展名为“ .js”的文件的内容类型设为“ application / javascript”。
本地主机
#Use to create local host
import SimpleHTTPServer
import SocketServer
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler.extensions_map.update({
".js": "application/javascript",
});
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "Serving at port", PORT
print(Handler.extensions_map[".js"])
httpd.serve_forever()
感谢Bergi帮助我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.