使用jQuery导入CSV文件

Does anyone know of a way to get data from a CSV file, then put it into an array which i can pass via AJAX to my webservice?

Replaced my entire answer with a nice jQuery solution:

$(document).ready(function() {
            var data = '"REVIEW_DATE","AUTHOR","ISBN","DISCOUNTED_PRICE"    "1985/01/21","Douglas Adams",0345391802,5.95    "1990/01/12","Douglas Hofstadter",0465026567,9.95   "1998/07/15","Timothy ""The Parser"" Campbell",0968411304,18.99 "1999/12/03","Richard Friedman",0060630353,5.95 "2001/09/19","Karen Armstrong",0345384563,9.95  "2002/06/23","David Jones",0198504691,9.95  "2002/06/23","Julian Jaynes",0618057072,12.50   "2003/09/30","Scott Adams",0740721909,4.95  "2004/10/04","Benjamin Radcliff",0804818088,4.95    "2004/10/04","Randel Helms",0879755725,4.50';

            var array1 = data.split("\t");
            var array2 = new Array();

            for (var i = 0; i < array1.length; i++) {
                array2.push(array1[i].split(","));
                for (var j = 0; j < array2[i].length; j++) {
                    $('ul').append('<li>'+array2[i][j]+'</li>');
                }               
                $('ul').append('<li><hr></li>');
            }
        });

Only difference is you will have to do the following to retrieve the CSV file...

   $.ajax({
      url: "file.csv",
      success: function(data) {
        var array1 = data.split("\t");
        var array2 = new Array();

        for (var i = 0; i < array1.length; i++) {
            array2.push(array1[i].split(","));
            for (var j = 0; j < array2[i].length; j++) {
                $('ul').append('<li>'+array2[i][j]+'</li>');
            }               
            $('ul').append('<li><hr></li>');
        }
      }
    });

FileReference and FileAPI are libraries available it most modern browsers. After receiving the file and getting access to it as an array of characters you can apply regex or split.

An example:

// this first part is from FileAPI
// it allows you access to files that
// the user has selected
var file = $('#file').get().files[0];
data = getAsText(file);

// assuming you'll use a semicolon as separator
// and you're not forcing all fields to be quoted
var an_array = data.split(";");

$.post('script.php', an_array, function(response) {
    // Do something with the response
}, 'json');

The getAsText() function is not part of the API, I read it from here and there's no reason to copy it entirely.

Search Can I Use . com