簡體   English   中英

如何從JavaScript中的目錄中選擇最新的txt文件

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

我想使用javascript從服務器中選擇最近修改的文件。

這是我的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
    });

這是從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>

再次感謝大家!

最好的解決方案是對您的PHP應用程序發出一個JavaScript GET請求,以處理對您Dropbox的訪問。

根據您的解釋,Dropbox僅在服務器端可見,並且您想公開客戶端的TXT文件,為解決當前問題,請添加PHP端方法來處理對您Dropbox的文件訪問並將其公開,以便您的客戶端JavaScript可以請求PHP應用程序中的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM