-1

Code:

<script>
    $(document).ready(function(){

        var filepath = 'csv/data.csv';                      
        var data_string = $.get(filepath);
        console.log(data_string);
    });
</script>

When I use console.log(data_string) I got the following output on the console.

When I read that, I found that "responseText" has the values which I want. So I just need to get "responseText" to another variable.

I tried var data = data_string.responseText. But it not worked.

enter image description here

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128

2 Answers2

2

You should attach a callback function to $.get. From your console i see that is a jqXHR Object. $.get method has a success callback function that is executed if the request succeeds.

Attaching a callback function includes automatically json parsed.

var filepath = 'csv/data.csv';    
$.get( filepath , function(response) {
   console.log(response);
});
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
0

You need to provide callback function to get response from server like below:

var filepath = 'csv/data.csv';    
$.get( filepath , function( data ) {
 console.log(data);
});
Rohan Fating
  • 2,135
  • 15
  • 24