0
var req = new XMLHttpRequest();
req.addEventListener('load', function (txt) {
  console.log(txt)
}, false);
req.open("get", "/foo.txt", true);
req.send();

I feel pretty stupid right now like I'm missing something obvious, but that above is returning 200 and the response has the contents of the file. The server logs show a successful request as well. However, txt is showing an XHR object with no responseText and 0 response length. The file is just a text file. I also tried changing it to .json just to see if it'd do something different.

4

1 回答 1

0

问题是我需要this.responseText在我的加载事件侦听器中,而不是txt.responseText.

于 2013-08-16T17:25:13.373 回答