dongmaoxi0477 2014-06-23 15:06
浏览 27
已采纳

如何在javascript中从目录中选择最新的txt文件

I want to select the most recently modified file from my server using javascript.

This is the code in my js files:

$.get('Dropbox/geo/sites/GC_ROOM/hassayampa.txt', function(data){   
        // Split the lines
        var lines = data.split('
');   
        // Iterate over the lines and add categories or series
        $.each(lines, function (lineNo, line) {
            var items = line.split('\t');
            if(lineNo !== 0) {
               var x = + new Date(items[0]),
                    primout = parseFloat(items[3] / 10.0),
                    secout = parseFloat(items[5] / 10.0);
                if(!isNaN(primout) && !isNaN(secout)){
                    options.series[0].data.push([x,primout]);
                    options.series[1].data.push([x,secout])
                }
            }
        });
        new Highcharts.Chart(options); // this is now in the $.get callback function
    });

Here is coding from the index.php file that views the js files:

<body width="100%">
    <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
    <script src="https://geoinc.org/css/GEOREMCO/graph/highcharts.js"></script>
    <script src="https://geoinc.org/css/GEOREMCO/graph/exporting.js"></script>
    <script src="monitor/SiteData/Data/Lane_Metals/GRAPH/LANE_METALS.js" type="text/javascript"></script>
    <script src="monitor/SiteData/Data/Lane_Metals/GRAPH/LOVELAND.js" type="text/javascript"></script>
    <script src="monitor/SiteData/Data/Lane_Metals/GRAPH/TEST.js" type="text/javascript"></script>
    <script src="monitor/SiteData/Data/Lane_Metals/GRAPH/APPLES.js" type="text/javascript"></script>
    <script src="monitor/SiteData/Data/Lane_Metals/GRAPH/EXAMPLE.js" type="text/javascript"></script>
    <script src="monitor/SiteData/Data/Lane_Metals/GRAPH/FRUIT.js" type="text/javascript"></script>
    <table border="0" cellspacing="5" cellpadding="0" width="10%" bgcolor="#E8E8E8">
        <tr>   
            <th><div id="TEST" style="width: 900px; height: 300px;"></div></th>
            <th><div id="EXAMPLE" style="width: 900px; height: 300px;"></div></th>
        </tr>
        <tr>
            <td><div id="LANE_METALS" style="width: 900px; height: 300px;"></div></td>
            <td><div id="FRUIT" style="width: 900px; height: 300px;"></div></td>
        </tr>
        <tr>
           <td><div id="LOVELAND" style="width: 900px; height: 300px;"></div></td>
           <td><div id="APPLES" style="width: 900px; height: 300px;"></div></td>
        </tr>
    </table>
</body>

Thanks again everyone!

  • 写回答

1条回答 默认 最新

  • dsiftnc99059 2014-06-23 15:45
    关注

    Your best solution for this would be to have a JavaScript GET request to your PHP application that handles access to your Dropbox.

    From what you explained your Dropbox is only visible serverside and you want to expose your TXT files client side, to solve your current problem add a method, PHP side, to handle file access to your dropbox and expose it so your client side JavaScript can request the contents from your PHP application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘