weixin_33701251 2014-03-25 07:51 采纳率: 0%
浏览 19

我该如何刷新我的网站?

I have in c# application that update a text file each few minutes with a different data inside.

For example first time in the text file there: Hello world After a minute the text file contain: Hi everyone

Now in the c# application i'm uploading the text file once it was change.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;

namespace ScrollLabelTest
{
    class FtpFileUploader
    {
        static string ftpurl = "ftp://ftp.test.com/files/theme/";
        static string filename = @"c:\temp\test.txt";
        static string ftpusername = "un";
        static string ftppassword = "ps";
        static string value;

        public static void test()
        {
            try
            {

                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(
                ftpurl + "/" + Path.GetFileName(filename));
                request.Method = WebRequestMethods.Ftp.UploadFile;


                request.Credentials = new NetworkCredential(ftpusername, ftppassword);


                StreamReader sourceStream = new StreamReader(@"c:\temp\test.txt");
                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                response.Close();
            }
            catch(Exception err)
            {
                string t = err.ToString();
            }
        }
    }
}

I see on my hard disk the text file is changed the content and also after uploading the file to my website ftp i see there the updated text file.

Now in my website i'm using javascript/ajax to read the uploaded text file:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>

<div id="oneliner">
    <div class="header"> Breaking News </div>
    <ul class="newsticker">
<script>
$(function() {
    var file = "http://newsxpressmedia.com/files/theme/test.txt";
    $.get(file, function (txt) {
        //var lines = txt.responseText.split("
");
        var lines = txt.split("
");
        $ul = $('<ul class="newsticker" />');
        for (var i = 0, len = lines.length; i < len; i++) {
            //save(lines[i]); // not sure what this does
            $ul.append('<li>' + lines[i] + '</li>');
        }
        //$ul.appendTo('body').newsTicker({
        $ul.appendTo('div.wcustomhtml').newsTicker({
            row_height: 48,
            max_rows: 2,
            speed: 6000,
            direction: 'up',
            duration: 1000,
            autostart: 1,
            pauseOnHover: 1
        });
    });
});
</script>
</ul>
</div>

The problem is once my application in c# updated the file and uploaded it to the ftp i need in my browser for example chrome to make manual refresh if not it will keep showing the old text file content and not the updated.

How can i make a refresh maybe in the javascript ?

  • 写回答

4条回答 默认 最新

  • weixin_33719619 2014-03-25 07:58
    关注

    Try like this

    No need to refresh the page just refresh the function that will get the latest info from text file

    $(function() {
        news();
        setInterval(function(){
          news()
        },60000)  // it will call every 1 min you can change it
    });
    
    function news(){
       $('body').find('.newsticker').remove();//It will clear old data if its present 
       var file = "http://newsxpressmedia.com/files/theme/test.txt";
        $.get(file, function (txt) {
            //var lines = txt.responseText.split("
    ");
            var lines = txt.split("
    ");
            $ul = $('<ul class="newsticker" />');
            for (var i = 0, len = lines.length; i < len; i++) {
                //save(lines[i]); // not sure what this does
                $ul.append('<li>' + lines[i] + '</li>'); //here 
            }
            //$ul.appendTo('body').newsTicker({
            $ul.appendTo('div.wcustomhtml').newsTicker({
                row_height: 48,
                max_rows: 2,
                speed: 6000,
                direction: 'up',
                duration: 1000,
                autostart: 1,
                pauseOnHover: 1
            });
        });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码