views:

636

answers:

1

I'm trying to use the jquery csv plugin to load a csv file into an array. However, firebug is not very happy with it.

Firebug keeps saying "not well-formed" when processing the csv file.

The csv file looks like this:

"PC0003","Windows XP Professional","2006/01/05"
"PC0002","Windows XP Professional","2006/01/10"
"PC0001","Windows XP Professional","2006/01/30

I'm trying to load it in my page like this:

var myFile = jQuery.get("output.csv", function(data) { array = jQuery.csv()(data); })

however if i try to explore my array in the DOM tree it seems like its all there. but when i try to enter in the firebug console:

console.debug(myFile[1]);

it says undefined.

is this firebug's fault or my code is wrong?

thanks in advance for your help.

+1  A: 

It's not well-formed because $.get() is expecting the wrong data-type.
http://docs.jquery.com/Ajax/jQuery.get
Use "text" for the data-type. Eg:

var myFile = jQuery.get("output.csv", function(data) { array = jQuery.csv()(data); }, "text")

Where are you breakpointing? myFile is scoped (only visible within it's containing function), so FireBug may not be able to see it. Remove the "var" in front of myFile and try again (this makes it global), or set a breakpoint right after myFile is set and try again.
You can also try replacing the code you have with this:

myFile = jQuery.get("output.csv", function(data) { array = jQuery.csv()(data); }, "text");
console.debug(myFile);
this is not working, same results. firebug keeps saying "not well-formed" and i can't do console.debug(myFile[1]); since it says its undefined.
Do not use console.debug in the console. Do it in the script right after var myFile is declared.Or just use console.debug(myFile);