gpt4 book ai didi

javascript - MVC中数据库查询后重新加载页面js

转载 作者:行者123 更新时间:2023-12-03 10:14:34 25 4
gpt4 key购买 nike

我有这样的脚本:

$(document).ready(function () {
$('#requestTable').DataTable(
{
aoColumns: [
{ mDataProp: "DateStart", sTitle: "Date Start" },
{ mDataProp: "DateEnd", sTitle: "Date End" },
{ mDataProp: "Approved", sTitle: "Approved" },
{ mDataProp: "Data", sTitle: "Employee" },
{ mDataProp: "Position", sTitle: "Position" },
{ mDataProp: "", sTitle: "" }
],
columnDefs: [{
targets: 'no-sort',
orderable: false
}]
});

$('button.accept-button').click(function () {
var id = $(this).attr('data-id')
$.ajax({
type: "POST",
url: "/TableRequest/AcceptRequest",
data: { 'id': id },
success: function (msg) {
}
});
location.reload(true);
});
var tempId;
$('button.decline-button').click(function () {
tempId = $(this).attr('data-id')
$("#dialog").dialog()
});
$('button.ok-request').click(function () {
var message = $('textarea#commentForDecline').val();

$.ajax({
type: "POST",
url: "/TableRequest/DeclineRequest",
data: { 'message': message, 'id': tempId },
success: function (msg) {
}
});
$("#dialog").dialog('close');
$('textarea#commentForDecline').val('');
location.reload(true);
});
});

如您所见,我在发布 Ajax 查询后重新加载页面。但是有没有办法检查数据库中的更改并在此之后刷新页面(调用 Action)?所以 Db 更改已经晚了,我想检查一下。

最佳答案

成功后可以重新加载页面,并从后端操作返回您要检查的数据,然后可以重新加载

success: function (data) {
console.log(data);
if (data.somekey === "somevalue"){
location.reload(true);
} else {
//don't reload show me some erros
}

}

关于javascript - MVC中数据库查询后重新加载页面js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29947072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com