Closed GoogleCodeExporter closed 9 years ago
It's failing because you're calling it on the wrong variable.
csvData, as defined in your code contains an object representing the jQuery
AJAX request not the data containing the contents of the response.
$.csv.toArray() works on strings, hence the requirement for the replace()
method (which is a method of the string prototype).
What you really want is the 'result' variable, which contains the csv data
string. You have demonstrated as much with the following statement.
alert(result); <= shows that CSV data loadad.
Here's what your code should look like:
var csvData = $.ajax({
type: "GET",
url: "my.csv",
dataType: "text",
error: function ( xhr, errorType, exception ) {
var errorMessage = exception || xhr.statusText;
alert( "There was an error loading your data file: " + errorMessage );
},
success: function (result) {
alert(result); <= shows that CSV data loadad
//alert($.type(result)); <= returns 'string'
//alert("done!"+ csvData.getAllResponseHeaders())
var myCSVArray = $.csv.toArrays(csvData); <= breaks.
//alert( $.toJSON(myCSVArray) );
}
});
Note: You also want to call toArrays() for multi-line CSV data since toArray()
is only designed to handle a single entry.
The parser isn't broken, you were just calling the wrong variable. I don't have
any good examples demonstrating jquery/AJAX usage but I plan on adding them in
the near future.
I'm going to mark this as fixed but leave it open for a bit so you can report
any other issues if the fix doesn't work.
Original comment by evanpla...@gmail.com
on 10 Oct 2012 at 9:27
Original comment by evanpla...@gmail.com
on 10 Oct 2012 at 9:28
Original comment by evanpla...@gmail.com
on 11 Oct 2012 at 4:08
Original issue reported on code.google.com by
gcho...@gmail.com
on 10 Oct 2012 at 8:14