问题描述
我正在寻求帮助。我是编程新手,我正在开发一个新项目。
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 textThe text file is located on my serverThe text content changes every three minutes or so.
我希望阅读此文件并在网页中显示其内容
网络浏览器将自动重新阅读每三分钟左右发一次文件。
I wish to read this file and display its content in a web pageThe 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 thanksColin
推荐答案
<!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>
这篇关于阅读文本文件并在网页中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!