Search code examples
javascriptcsshtmlpapaparse

ReferenceError: Papa is not defined


so I'm trying to setup PapaParser to parse a CSV file onto arrays that I can later use with another script to make graphs. So far I just want to paste the strings from my arrays onto the blank div, so I can see what's going on. I am new to this and have no idea how to import javascript libraries, so I copied the files into my public_html folder. Now NetBeans seems to see them.

Long story short I'm stuck at the beginning, I get a reference of ReferenceError: Papa is not defined when I try to run my parser.

Any input or a link to a tutorial on how to do this would be greatly appreciated (tried googling, found nothing of use). I've added my code so far...

Papa.parse("TopPercentilesCSV.csv", {
		complete: function(results) {
			console.log("Finished:", results.data);
		}
	});
.displaypanel {
    border: 1px solid black;
    width:400px;
    height:400px;
    margin:auto;
}
<!DOCTYPE html>

<html>
    <head>
        <title>Parsing CSV test</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link type="text/css" rel="stylesheet" href="index.css"/>
        <script type="text/javascript" src="index.js"></script>
        <script src="PapaParse/papaparse.js"></script>
    </head>
    <body>
        <div class="displaypanel">            
        </div>
    </body>
</html>


Solution

  • Change your code to this:

    <!DOCTYPE html>
    
    <html>
        <head>
            <title>Parsing CSV test</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <link type="text/css" rel="stylesheet" href="index.css"/>
            <script src="PapaParse/papaparse.js"></script>
            <script type="text/javascript" src="index.js"></script>
    
        </head>
        <body>
            <div class="displaypanel">            
            </div>
        </body>
    </html>
    

    First you have to include the library, then you can call function defined inside