weixin_33738578 2016-10-13 03:13 采纳率: 0%
浏览 74

GET功能控制台错误

The logic:

my_function looks through file.txt, if it finds the word "Hello", returns true. If not, false.

The problem:

Uncaught type error: contents.includes is not a function

Limitations:

Can only use plain javascript

function my_function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(contents) {
if (this.readyState == 4 && this.status == 200) {
//contents variable now contains the contents of the textfile as string

//check if text file contains the word Hello
var hasString = contents.includes("Hello");

//outputs true if contained, else false
console.log(hasString);

}
};
xhttp.open("GET",  "http://www.example.com/file.txt", true);
xhttp.send();
}
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有偿找一份verilog语言的cnn代码带讲解
      • ¥15 关于#mysql#的问题:mysql 组内排名,取各组的销售金额前10
      • ¥15 有人用过颜色传感器吗?
      • ¥50 求一个SQL长料切短料的优化排版算法
      • ¥15 python 删除TXT文档中小写字母
      • ¥15 ValueError: not enough values to unpack (expected 2, got 0)
      • ¥15 js怎么禁止修改域名
      • ¥15 Cursor为什么在Windows11打不开
      • ¥30 java调用javacv遇到的问题
      • ¥15 如何使用matlab画出带宽100Khz,时长100ms信号的LFM形式的时频图啊