Display sharepoint list to preformatted excel sheet when clicked on button using JSON ,javascript or Jquery

Display sharepoint list to preformatted excel sheet when clicked on button using JSON ,javascript or Jquery

I have a sharepoint list which i want to export to preformatted excel sheet when clicked on a button.
I want JSON values of list to be converted to Excel sheet.However I tried below mentioned code but in new window  page was blank and we were getting tags in URL part.
<div id = "exportToExcel" >

<table>
<tr>
   
<th> Col1 </th>
</tr>
<tr>
   
<td> row1 </td>
</tr>
<tr>
   
<td> row2 </td>
</tr>
 
<tr>
   
<td> row3 </td>
</tr>
</table>
</div>
<input type = "button" id = "btnExcel" value = "Export to Excel" />

Jquery

$("#btnExcel").on('click', function(e) { window.open('data:application/vnd.ms-excel,' + $('#exportToExcel').html()); e.preventDefault(); 
I would like to get more help on below mentioned part
 window.open('data:application/vnd.ms-excel,' + $('#exportToExcel').html());