Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript读取文件_Javascript_Jquery_Html - Fatal编程技术网

Javascript读取文件

Javascript读取文件,javascript,jquery,html,Javascript,Jquery,Html,嗨,我希望有人能帮我: 我创建了一个bash脚本,通过FTP连接到我的免费网络主机,并上传一个file.txt文件 进入主目录。我想做的是阅读此文本并将其显示在index.html网站上 环顾四周,我看到了以下脚本: jQuery.get('path/to/file/on/server.txt', null, function(data, status) { // your file contents are in 'data' }); 如何输出“数据” 或者有没有其他方法可以推荐 多

嗨,我希望有人能帮我:

我创建了一个bash脚本,通过FTP连接到我的免费网络主机,并上传一个file.txt文件 进入主目录。我想做的是阅读此文本并将其显示在index.html网站上

环顾四周,我看到了以下脚本:

jQuery.get('path/to/file/on/server.txt', null, function(data, status) {
    // your file contents are in 'data'
});
如何输出“数据”

或者有没有其他方法可以推荐

多谢各位

$.get("file.txt", function(data){
  alert("Data Loaded: " + data);
});
编辑:取自


编辑:取自

获取file.txt的内容并显示在id为“id”的div中:


获取file.txt的内容并显示在id为“id”的div中:

$.get("file.txt", function(data){
   $("#id").text(data);
});