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.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改