0

I'm not sure if I'm gettin it right but I just started to use this jQuery-CSV parser plugin. I wanted to parse CSV file I have stored locally and then, based on results I get from it, use either jQuery's or ajax's notation to get certain data out of urls I provide.

var $ = jQuery = require('jQuery')
require ('./jquery.csv.js')

var sample = './analytics.csv';
fs.readFile(sample, 'UTF-8', function(err, csv) {
    $.csv.toObjects(csv, {}, function(err, data) {
        for(var i=0, len=data.length; i<len; i++) {
            var link = toLink(data[i].Page)
            $.get( link, function(data){
                data[i].Category = $('.category').get(0)
            });

            console.log(data[i])
        }
    });
});

I'm getting back an error:

$.get(link, function (data){
  ^

TypeError: $.get is not a function
at main (E:\Programowanie\lolStats\index.js:16:7)
at Object.<anonymous> (E:\Programowanie\lolStats\index.js:37:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)

It seems to me like it's looking for get() function in the jquery.csv.js file instead of regular jquery module I've installed for this project. What would be the easiest way to make both .csv.functions and regular jquery ones work in a same file?

Evan Plaice
  • 13,944
  • 6
  • 76
  • 94
PlainLazy
  • 67
  • 1
  • 6
  • I think the problem is that `var $ = jQuery = require('jQuery')` doesn't work. Can you verify that after that line `$` has a value and looks like jQuery? – Halcyon Mar 24 '17 at 15:28
  • I think the first line is meant to be `var $ = jQuery = require('jquery')` (note the lowercase require name) – BenShelton Mar 24 '17 at 15:29
  • 'jQuery' has been taken straight from plugin's examples. I've already tried lowercase notation. Doesn't change a thing. – PlainLazy Mar 24 '17 at 15:34
  • @Halcyon yes, I think you may be right. I could've been using wrong jquery module (or a wrong version). Other than that, I may also need to use 'jsdom' to make it work in the end. – PlainLazy Mar 24 '17 at 15:52

0 Answers0