简体   繁体   中英

Read text in java script

What is a typical method for reading text files in 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.

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.

Resource interpreted as Script but transferred with MIME type 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.

Configure your web server to transfer *.vp files as x-shader/x-vertex .

For example in apache you would configure something like this in your .htaccess file:

AddType x-shader/x-vertex vp

Other web servers have their own ways to configure this. IIS Documentation is here if you're using it.

我想我真正想要的是XmlHttpRequest。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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