Here is my relevant jQuery code:
$.get('sampleData.csv', function(data) {
var lines = data.split('\r\n');
The first few line of the sampleData.csv file look like this:
2009,0,2,29.0000
2009,0,6,655.6200
I get 2 errors.
On the first line of csv file I get the error
syntax error
On the 2nd line of code I get the error
data.split is not a function
What am I doing wrong?
ETA According to the firebug console, the responseText is the following:
2009,0,2,29.0000\r\n2009,…\r\n2011,10,30,494.3500\r\n
ETA I added an alert of the data before I try splitting it into lines, and I get the following:
[Object XMLDocument]
I believe you misunderstand what jQuery.get() is suppose to be used for.
From it’s doc page,
"...Load data from the server using a HTTP GET request...."Doing a $.get() on a file will not get you that file’s data into a structure that can be used. You have to request this through a server which will then provide the .csv data … it should look something like the following
EDIT::
Since you say the data is being ‘loaded’ properly, try this fiddle. It works just fine.
EDIT2::
Your last edit gave some interesting insight. When it pulls the .csv file, its converting it to a type of XML vs text. Try the following:
This should put the returning ‘data’ into the proper string format.