Unable to read csv file from Amazon s3

Viewed 56

My requirement is to read the csv file from Amazon s3 using javascript and to make it as html table data. I have tried the following html code but it was not working:

     <script>
    $(document).ready(function(){
     $('#load_data').click(function(){
     alert("inside click");
      $.ajax({
       url:"https://s3Url/TestData_CSV.csv",
       dataType: "jsonp",
            crossDomain: true,
            headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Headers": "origin, content-type, accept"
        }, 
       success:function(data)
       {
        var tbl_data = data.split(/\r?\n|\r/);
        for(var count = 0; count<tbl_data.length; count++)
        {
         var cell_data = tbl_data[count].split(",");
         table_data += '<tr>';
         for(var cell_count=0; cell_count<cell_data.length; cell_count++)
         {
          if(count === 0)
          {
           table_data += '<th>'+cell_data[cell_count]+'</th>';
          }
          else
          {
           table_data += '<td>'+cell_data[cell_count]+'</td>';
          }
                }
         }
         table_data += '</tr>';
         table_data += '</table>';
        $('#tbl_details').html(table_data);
        }
        
       });
      });
     });
    </script>
 <html>
     <head>
      <title>Details</title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
       <link rel="icon" href="data:;base64,=">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
     </head>
     <body>
      <div class="container">
       <div class="table-responsive">
        <h1 align="center">Details</h1>
        <br />
        <div align="center">
         <button type="button" name="load_data" id="load_data" class="btn btn-info">Load Data</button>
        </div>
        <br />
        <div id="tbl_details">
        </div>
       </div>
      </div>
     </body>

    </html>

But,I was getting net::ERR_ABORTED 403 (Forbidden) error on running the html. Can anyone please help me with it.

0 Answers
Related