如何在 asp.net 中使用 JSON 自动完成将值插入 jquery 获取的数据库
本文关键字:插入 jquery 数据库 获取 asp net JSON | 更新日期: 2023-09-27 18:30:25
它可能回应谁,
我们尝试将数据插入到 Oracle DBMS,通过调用 Web 服务由 JSON 获取 asp.net。在这里,aspx页面是来自另一个堆栈溢出答案的修改代码。我们是否必须再次使用 JSON 将值发送到代码隐藏?如果是这样,如何?
感谢示例脚本
的 http://www.codingfusion.com/Post/Jquery-JSON-Add-Edit-Update-Delete-in-Asp-Net
感谢您的关注
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="test7._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Scripts>
<asp:ScriptReference Path="Scripts/jquery-1.11.1.min.js" />
<asp:ScriptReference Path="Scripts/jquery-ui.min.js" />
</Scripts>
</asp:ScriptManagerProxy>
<div id="outer" style="width: 100%; background-color: #737CA1">
<div id="HeadDiv" style="width: 90%; background-color: #737CA1">
<script type="text/javascript" id="ButceList">
$(function () {
$("#txtButce").autocomplete({
source: function (request, response) {
var param = { prefixText: $('#txtButce').val() };
$.ajax({
url: "Default.aspx/GetButce",
data: JSON.stringify(param),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 2//minLength as 2, it means when ever user enter 2 character in TextBox the AutoComplete method will fire and get its source data.
});
});
</script>
<script type="text/javascript" id="TipList">
$(function () {
$("#txtTip").autocomplete({
source: function (request, response) {
var param = { prefixText: $('#txtTip').val() };
$.ajax({
url: "Default.aspx/GetTip",
data: JSON.stringify(param),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 2//minLength as 2, it means when ever user enter 2 character in TextBox the AutoComplete method will fire and get its source data.
});
});
</script>
<script type="text/javascript">
function openModalForm() {
window.showModalDialog('Details.aspx', '', 'status:1; resizable:1; dialogWidth:900px; dialogHeight:500px; dialogTop=50px; dialogLeft:100px')
}
</script>
<script type="text/javascript">
function saveData() {
//==== Call validateData() Method to perform validation. This method will return 0
//==== if validation pass else returns number of validations fails.
//var errCount = validateData();
//==== If validation pass save the data.
var txtButce = $("#txtButce").val();
var txtTip = $("#txtTip").val();
$.ajax({
type: "POST",
url: "Default.aspx/saveData",
data: JSON.stringify({butce:txtButce,tip:txtTip}),
contentType: "application/json; charset=utf-8",
datatype: "jsondata",
async: "true",
success: function (response) {
$(".errMsg ul").remove();
var myObject = eval('(' + response.d + ')');
if (myObject > 0) {
$(".errMsg").append("<ul><li>Data kaydedildi</li></ul>");
}
else {
$(".errMsg").append("<ul><li>Kayıt işleminde hata olustu, tekrar deneyiniz.</li></ul>");
}
$(".errMsg").show("slow");
clear();
},
error: function (response) {
alert(response.status + ' ' + response.statusText);
}
});
}
</script>
<div class="ui-widget">
<label for="txtButce" >Bütçe Kodu/Lokasyon: </label>
<input id="txtButce">
<br />
<label for="txtTip">Tip/Alttip: </label>
<input id="txtTip" />
</div>
<asp:Label ID="lblDateInfo" runat="server" Style="color: White;" /><br />
<asp:Button ID="btnCalShow" runat="server" Text="Tarih Seçiniz" />
<asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" />
</div>
<br />
<asp:Button ID="btnPenaltyCalculate" Text="Hesapla" runat="server" Style="margin-left: 0px; margin-top: 5px; margin-bottom: 5px;" />
<asp:Button ID="btnPenaltySubmit" Text="Kaydet" runat="server" Style="margin-left: 5px; margin-top: 5px; margin-bottom: 5px;" />
<%-- %> <asp:Button ID="btnRefresh" runat="server" Text="Haftayı yeniden yükle" style="margin-left:60px;margin-top:5px;margin-bottom:5px;" />
--%>
</div>
</asp:Content>
您需要对
WebMethod
(或 asp.net 回发)执行另一个 AJAX POST 以将数据发送回服务器,然后服务器可以更新您的数据库。