We can use different technique to fetch data from SharePoint List.
Here, I am using jQuery to fetch data from a share point list.
HTML file-
<table id="tblData"> <thead> <tr> <th>EmployeeName </th>
<th>Designation</th>
<th onClick="sortTable(1)">Email</th>
<th>Salary</th>
<th>GrossSalary</th>
<th>Contact Number</th>
<th>Company</th> </tr>
</thead>
<tbody> </tbody> </table>
JSfile-
<script>
$.ajax({
url:SITE URL+"/_api/Web/Lists/getbytitle('LISTNAME')/items",
method:"GET",
headers: { "accept": "application/json;odata=verbose", //It defines the Data format
"content-type": "application/json;odata=verbose" //It defines the content type as JSON
},
success:function(response){
console.log(response);
response.d.results.forEach(function(d,key){
console.log(d);
var html = "<tr><td>" + d.EmployeeName + "</td><td>" + d.Designation + "</td><td>" + d.Email + "</td> <td>" + d.Salary+ "</td><td>" + d.GrossSalary+ "</td> <td>" + d.contactNumber+ "</td><td>" + d.Company+ "</td> </tr>"
$(table tbody).append(html);
)}
},
error:function(error){
console.log(JSON.stringify(error));
}
});
</script>
Here, I am using jQuery to fetch data from a share point list.
HTML file-
<table id="tblData"> <thead> <tr> <th>EmployeeName </th>
<th>Designation</th>
<th onClick="sortTable(1)">Email</th>
<th>Salary</th>
<th>GrossSalary</th>
<th>Contact Number</th>
<th>Company</th> </tr>
</thead>
<tbody> </tbody> </table>
JSfile-
<script>
$.ajax({
url:SITE URL+"/_api/Web/Lists/getbytitle('LISTNAME')/items",
method:"GET",
headers: { "accept": "application/json;odata=verbose", //It defines the Data format
"content-type": "application/json;odata=verbose" //It defines the content type as JSON
},
success:function(response){
console.log(response);
response.d.results.forEach(function(d,key){
console.log(d);
var html = "<tr><td>" + d.EmployeeName + "</td><td>" + d.Designation + "</td><td>" + d.Email + "</td> <td>" + d.Salary+ "</td><td>" + d.GrossSalary+ "</td> <td>" + d.contactNumber+ "</td><td>" + d.Company+ "</td> </tr>"
$(table tbody).append(html);
)}
},
error:function(error){
console.log(JSON.stringify(error));
}
});
</script>
Comments
Post a Comment