所以我正在尝试读取外部(如来自不同域的)文本文件,但我尝试过的任何内容都不起作用。通常发生的是响应是undefined,或者根本没有。这是我尝试过的一件事:// package xmlhttprequest is installed// this was copy-pasted from some other stackoverflow questionvar XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;var txtFile = new XMLHttpRequest();txtFile.open("GET", "https://snappeathing282346239557829348747259837723489.000webhostapp.com/pin.txt", true);txtFile.onreadystatechange = function() { if (txtFile.readyState === 4) { // Makes sure the document is ready to parse. if (txtFile.status === 200) { // Makes sure it's found the file. allText = txtFile.responseText; lines = txtFile.responseText.split("\n"); // Will separate each line into an array } }}console.log(txtFile.send(null)) // Logs response to console我得到的回应是undefined,我怎样才能得到 123(123 是 txt 文件包含的内容)而不是记录undefined?
添加回答
举报
0/150
提交
取消