阅读文本文件并在网页中显示 [英] Read text file and display in web page

查看:347
本文介绍了阅读文本文件并在网页中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求帮助。我是编程新手,我正在开发一个新项目。

I am seeking some help. I am very new to programming and I’m working on a new project.

目标是在网页中显示纯文本文件的内容。

The objective is to display the contents of a plain text file in a web page.

文本文件(名为title.txt)并有一行文本
文本文件位于我的服务器上
文本内容每隔三分钟更改一次。

The text file (named title.txt) and has a single line of text The text file is located on my server The text content changes every three minutes or so.

我希望阅读此文件并在网页中显示其内容
网络浏览器将自动重新阅读每三分钟左右发一次文件。

I wish to read this file and display its content in a web page The web browser is to automatically re-read the file every three minutes or so.

我已经看了很多网站来实现这个目标,但我对可用的选项感到困惑。我读到Jquery / ajax可以执行此任务。

I have looked at a number of websites to achieve this, however i am confused by the options available. I read that Jquery/ajax can perform this task.

任何人都可以通过提供一些示例代码来帮助我。

Can anyone help me by providing some example code.

非常感谢
Colin

Many thanks Colin

推荐答案

<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
</head>

<Body>

<p><center>Current Track: <span id="trackinfo">No track information available at this time</span></p></center>

<script>
function radioTitle() {

var url = 'http://XXX.no-ip.org:8000/tracktitle.txt'; 

$.ajax({
   type: 'GET',
   url: url,
   dataType: 'text',
   success: function(data) {

   $("#trackinfo").html(data)
},

error: function(e) {
   console.log(e.message);
}

});

}

$(document).ready(function(){

setTimeout(function(){radioTitle();}, 2000);
setInterval(function(){radioTitle();}, 15000);

});

</script>

</body>
</head>
</html>

这篇关于阅读文本文件并在网页中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆