2

Im having issues with reading a csv file using jquery ajax.I have two csv files with the same content.we are using the below code to get the data from the csv file.

$(document).ready(function()
    {
        $.ajax({
            type : "GET",
            url : "data/application_index1.csv",
            dataType : "text",
            async : false,
            success : 
        function(data)
            {
                console.log(data)
                all_application = CSVToArray(data);
            }
        });

    });

The data count of the csv file is 8.when we are converting the data from the csv file to array,we are getting length of the array as 8 (for one csv file). and for the other csv file the length is 9. Upon debugging the code, below is the data obtained from the csv file (correct one)

"index,application_name
1,Friday Daily Jobs WK1
2,Monday Additional Jobs 
3,"Monday Daily Jobs
"
4,Non Daily Jobs
5,NonBATCHNDC Daily Jobs
6,Others
7,Tue-Fri Daily"

when we convert the above to arrays, we get the length of the array as 8. which is correct. But when we use the other csv file the data we get is the below

"index,application_name
1,Friday Daily Jobs WK1
2,Monday Additional Jobs
3,Monday Daily Jobs
4,Non Daily Jobs
5,NonBATCHNDC Daily Jobs
6,Others
7,Tue-Fri Daily
"

Above is the data that we get when I debug the code.When we convert the above to array, the length of the array becomes 9.The quotes('"') displayed at the last line of the data is considered as one more array. Can someone please explain the reason for the same. Also it would be great how the data is read from the url specified in the ajax() function.

AnyHelp on this is much appreciated. Thanks

vr3w3c9
  • 1,118
  • 8
  • 32
  • 57
  • Take a look to the answer I made on this similar question: http://stackoverflow.com/a/35911600/5119765 – ADreNaLiNe-DJ Mar 15 '16 at 08:42
  • 1. The two files are not the "same content" and the 2nd has a blank line at the end. 2. Your (unprovided) `CSVToArray` method just need to ignore blank lines. (or a blank line with at least once space) – freedomn-m Mar 15 '16 at 08:42
  • kindly refer http://stackoverflow.com/questions/7431268/how-to-read-data-from-csv-file-using-javascript – RRR Mar 15 '16 at 08:58

0 Answers0