私は現在、新しい開発に取り組んでおり、プロジェクトに必要な滑らかな感触が本当に必要なので、SQL Server 2008 からデータを取得するために Ajax または jQuery を使用することを考えました。JSON とその機能は初めてです。
html は次のとおりです。
Enter Employee ID
<br />
<asp:TextBox ID="txtEmpId" runat="server"></asp:TextBox>
<br />
<input type="button" id="BtnSearch" runat="server" value="Search" />
<div id="emp" style="display: none; margin-top: 40px">
ID:<span id="txtId"></span><br />
Title:<span id="txtTitle"></span><br />
Name:<span id="txtName"></span><br />
Department:<span id="txtDepartment"></span><br />
</div>
Ajax は次のようになります。
<script type="text/javascript">
$(document).ready(function () {
$("#MainContent_BtnSearch").click(function () {
$("#emp").hide("slow");
var empId = $("#MainContent_TxtEmpId").val();
$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json",
url: "",
data: "{'employeeId': '" + empId.toString() + "'}",
success: function (data) {
$("#txtId").html(data.d.ID);
$("#txtName").html(data.d.FullName);
$("#txtTitle").html(data.d.Title);
$("#txtDepartment").html(data.d.Department);
/// show employee details
$("#emp").show("slow");
},
error: function () {
alert("Error calling the web service.");
}
});
});
});
SQL Server 2008 のデータベースからデータを取得し、そのレコードを更新してデータベースの変更を保存できるようにコードを改善する方法はありますか?