简体   繁体   English

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

[英]How to select most recent txt file from directory in javascript

I want to select the most recently modified file from my server using javascript. 我想使用javascript从服务器中选择最近修改的文件。

This is the code in my js files: 这是我的js文件中的代码:

$.get('Dropbox/geo/sites/GC_ROOM/hassayampa.txt', function(data){   
        // Split the lines
        var lines = data.split('\n');   
        // 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: 这是从index.php文件中查看js文件的代码:

<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! 再次感谢大家!

Your best solution for this would be to have a JavaScript GET request to your PHP application that handles access to your Dropbox. 最好的解决方案是对您的PHP应用程序发出一个JavaScript GET请求,以处理对您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. 根据您的解释,Dropbox仅在服务器端可见,并且您想公开客户端的TXT文件,为解决当前问题,请添加PHP端方法来处理对您Dropbox的文件访问并将其公开,以便您的客户端JavaScript可以请求PHP应用程序中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM