2

ローカル ディレクトリからいくつかのデータを解析しようとしています。私はそれを行うためにパパパーサーを使用します。問題は、テキスト ファイルを変数に代入できないことです。このエラーが発生しています。

キャッチされていない TypeError: 'FileReader' で 'readAsText' を実行できませんでした: パラメータ 1 はタイプ 'Blob' ではありません。

私はそれについて検索しましたが、HTML file reader でファイルを読み取るときに非常に一般的なエラーであることがわかりました。

私のコードは;

<!doctype html>
<html class="no-js" lang="">
    <head>
        <script src="https://github.com/mholt/PapaParse/blob/master/papaparse.js"></script>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Parse Example</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
    </head>
    <p>Click the button to Upload .</p>
    <button onclick="myFunction()" type="INPUT">Load</button>
    <input type="file" name="datafile" size="40">
    <script>
        var x;
        var config = {
            delimiter: "",	// auto-detect
            newline: "",	// auto-detect
            header: true,
            dynamicTyping: false,
            preview: 0,
            encoding: "",
            worker: false,
            comments: false,
            step: undefined,
            complete: undefined,
            error: undefined,
            download: true,
            skipEmptyLines: false,
            chunk: undefined,
            fastMode: undefined,
            beforeFirstChunk: undefined,
            withCredentials: undefined
        };
        function myFunction() {
            x = document.getElementsByName("datafile");
            myfile =  Papa.parse(x, config);
            document.getElementById("demo").innerHTML = myfile;
        }
    </script>
    <p id="demo"></p>
    </body>
</html>

4

1 に答える 1