简体   繁体   English

读取Java脚本中的文本

[英]Read text in java script

What is a typical method for reading text files in javascript? 在javascript中读取文本文件的典型方法是什么? The file will be located on the server like the rest of the script files, but I want to use it as GLSL shaders for instance. 该文件将与其余脚本文件一样位于服务器上,但是我想将其用作GLSL着色器。

I thought I could simply replace this: 我以为我可以简单地替换为:

<script id="shader-vs" type="x-shader/x-vertex">
    //GLSL code
</script>

with this line: 用这一行:

<script id="shader-vs2" type="x-shader/x-vertex" src="../Data/Effects/Shader.vp"></script>

When I tried it on Chrome it resulted in the following error. 当我在Chrome上尝试时,导致以下错误。

Resource interpreted as Script but transferred with MIME type application/octet-stream: "https://c9.io/b_old/substitute/workspace/Data/Effects/Shader.vp". 资源被解释为脚本,但以MIME类型application / octet-stream传输:“ https://c9.io/b_old/substitute/workspace/Data/Effects/Shader.vp”。

How should this be done? 应该怎么做?

I suppose what I really want is a XmlHttpRequest. 我想我真正想要的是XmlHttpRequest。

Configure your web server to transfer *.vp files as x-shader/x-vertex . 配置您的Web服务器以将* .vp文件作为x-shader/x-vertex传输。

For example in apache you would configure something like this in your .htaccess file: 例如,在apache中,您可以在.htaccess文件中配置以下内容:

AddType x-shader/x-vertex vp

Other web servers have their own ways to configure this. 其他Web服务器具有自己的配置方式。 IIS Documentation is here if you're using it. 如果您使用的是IIS文档 ,请点击这里。

我想我真正想要的是XmlHttpRequest。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM