简体   繁体   中英

200 Request but no responseText and content length of 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.

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

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