I need to read then contents of a CSV file from the local server. In my CSV file I have three fields, those are:
- Region,
- Acct_Name,
- State.
while getting the values in Acct_Name values are in the format of comma. In my CSV file reader it is separating comma and that value is going to state.
So how can I solve that issue?
My code is:
$(document).ready(function() {
 // AJAX in the data file
    $.ajax({
        type: "GET",
        url: "data.csv",
        dataType: "text",
        success: function(data) {processData(data);}
        });
    // Let's process the data from the data file
    function processData(data) {
        var table = $("<table />");
                    var rows = data.split(/\r\n|\n/);
                    for (var i = 1; i < rows.length-1; i++) {
                        var row = $("<tr />");
                        var cells = rows[i].split(",");
                        for (var j = 0; j < rows.length; j++) {
                            var cell = $("<td />");
                            cell.html(cells[j]);
                            row.append(cell);
                        }
                          var usedNames = {};
                            $("select[name='company1'] > option").each(function () {
                                if(usedNames[this.text]) {
                                    $(this).remove();
                                } else {
                                    usedNames[this.text] = this.value;
                                }
                            });
                              $("select[name='company2'] > option").each(function () {
                                if(usedNames[this.text]) {
                                    $(this).remove();
                                } else {
                                    usedNames[this.text] = this.value;
                                }
                            });
                                $("select[name='company3'] > option").each(function () {
                                if(usedNames[this.text]) {
                                    $(this).remove();
                                } else {
                                    usedNames[this.text] = this.value;
                                }
                            });
                            $("#region").append("<option value =1> " + cells[0] + " </option>");
                            $("#state").append("<option value =1> " + cells[1] + "</option>");
                            $("#accname").append("<option value =1>" + cells[2] + "</option>");
                        table.append(row);
                    }
    }
});
 
    