<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function getProducts() {
$.getJSON("api/Products", function (data) {
$('#products').empty(); //Clear the table body.
$.each(data, function (key, item) {
var row = '<td>' + item.Name + '</td><td>' + item.Price + '</td>';
$('<tr/>', { html: row }) //append the name
.appendTo($('#products'));
})
})
}
$(document).ready(getProducts);
</script>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>Products</h2>
<table>
<%--表格头--%>
<thead>
<tr>
<th>Name</th><th>Price</th>
</tr>
</thead>
<%--表格体--%>
<tbody id="products">
</tbody>
</table>
</asp:Content>