-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadText.js
35 lines (31 loc) · 970 Bytes
/
readText.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @fileoverview This file is used to read in the teapot_0.obj file for setting up the
* teapot buffers. This file is not dependent upon any other file.
*/
/**
* Gets a file from the server for processing on the client side.
*
* @param file A string that is the name of the file to get
* @param callbackFunction The name of function (NOT a string) that will receive a string holding the file
* contents.
*
*/
function readTextFile(file, callbackFunction)
{
console.log("reading "+ file);
var rawFile = new XMLHttpRequest();
var allText = [];
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
callbackFunction(rawFile.responseText);
console.log("Got text file!");
}
}
}
rawFile.send(null);
}