【发布时间】:2019-12-02 07:54:49
【问题描述】:
在这里,我应该单击复选框,然后使用提交按钮 (AJAX) 将数据发送到数据库。单击提交按钮后,它将刷新页面,但所有选中的复选框都消失了。刷新页面后如何保留选中的复选框?有什么想法或指导吗?
AJAX
//AJAX call for button
$("#primaryTextButton").kendoButton();
var button = $("#primaryTextButton").data("kendoButton");
button.bind("click", function(e) {
var test = $("#dropdown").val()
$.ajax({
url: "../DesignationProgramTemplate/getTemplate.php",
type: "post",
data: {'id':test,'progid':array},
success: function () {
// you will get response from your php page (what you echo or print)
kendo.alert('Success'); // alert notification
//refresh
//location.reload("http://hq-global.winx.ehors.com:9280/ehors/HumanResource/EmployeeManagement/DesignationProgramTemplate/template.php");
},
});
});
获取模板的 PHP
$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$id = $_POST['id'];
$progid = $_POST['progid'];
for($x=0; $x< sizeof($progid); $x++ )
{
$array = array();
$positionTemplateID = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplate");
$sqlAdd = "INSERT INTO tblHrsPositionProgramTemplate
SET positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW() ";
$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
$positionTemplateIDLog = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplateLog");
$sqlAddLog = "INSERT INTO tblHrsPositionProgramTemplateLog
SET positionTemplateIDLog = '" . $positionTemplateIDLog . "',
positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW() ";
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}
复选框的功能
function checkedNodeIds(nodes, checkedNodes) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].checked) {
//checkedNodes.push(nodes[i].moduleID);
// checkedNodes.push(nodes[i].groupID);
checkedNodes.push(nodes[i].id);
}
if (nodes[i].hasChildren) {
checkedNodeIds(nodes[i].children.view(), checkedNodes);
}
}
}
复选框检查
function toggleCheckAll() {
var checkButtonValue = $("#chbAll").val();
if(checkButtonValue == "Uncheck"){
$("#AccountingTree .k-checkbox-wrapper input").prop("checked", true).trigger("change");
$("#AdminSystemTree .k-checkbox-wrapper input").prop("checked", true).trigger("change");
$("#chbAll").val("Check");
} else {
$("#AccountingTree .k-checkbox-wrapper input").prop("checked", false).trigger("change");
$("#AdminSystemTree .k-checkbox-wrapper input").prop("checked", false).trigger("change");
$("#chbAll").val("Uncheck");
}
}
HTML
<div class="selectAll">
<input type="checkbox" id="chbAll" value="Uncheck" class="k-checkbox" onchange="toggleCheckAll()" />
<label class="k-checkbox-label" for="chbAll">Select All</label>
有人知道吗?
【问题讨论】:
-
一个想法,它与所有选定的会话链接
-
你能举个例子吗?
-
例如,当您发送到数据库时,您使用的是 PHP,在这种情况下,您可以将
nodes[i].id保存在会话中,例如,如果您正在迭代复选框,如果您发现,添加到会话中,例如:SESSION['somesession'] .= nodes[i].id .';' -
我需要创建新会话吗?
-
仅 1 次链接所有会话,例如以
';'分隔。 nodeid1;nodeid2...
标签: javascript php ajax checkbox