jQuery将本地服务器上的文本文件加载到DIV [英] jQuery loading text file on local server to DIV
问题描述
我希望jQuery定期将服务器上的文本文件加载到名为testMonitor
I want jQuery to periodically load a text file located on my server into a div called testMonitor
<script type="text/javascript">
$(function () {
$('#testMonitor').everyTime(500, function (i) {
var file = '/testsite/test_1.0/stream.txt';
$.get(file, function (data) {
$('#testMonitor').text(data);
});
});
});
</script>
当我在浏览器中导航到testsite/test_1.0/stream.txt
时,我看到了该文本文件的全部内容,因此该文件没有丢失/损坏...但是我的div完全显示为空.我浏览了关于SO的几乎所有问题,这些问题与在JS/jQ中加载txt/html文件有关,但是没有任何效果.有什么想法吗?
When I navigate to testsite/test_1.0/stream.txt
in my browser, I see the text file in all its glory so the file is not missing/broken... but my div shows up completely empty. I've browsed through almost all the questions on SO related to loading a txt/html file in JS/jQ but nothing has worked. Any ideas?
everyTime源自 jQuery计时器插件.这本身并没有被打破,因为我已经在div中测试了EveryTime的示例代码,并且确实确实按预期运行.
everyTime derives from the jQuery timer plugin. This isn't broken in and of itself, because I have tested the sample code for everyTime in my div and it does indeed behave as expected.
推荐答案
在您的浏览器中,您从下面访问URL
In your browser you are accessing url from below
testsite/test_1.0/stream.txt
您正在访问的脚本
/testsite/test_1.0/stream.txt
将斜线放在前面,只需将位置更新为真实位置即可.
with the slash in front, just update location into real one and it will work.
这篇关于jQuery将本地服务器上的文本文件加载到DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!