jQuery to pass Checkbox Update mysql
jQuery to pass Checkbox Update mysql
我在使用复选框更新 mysql 表的 jquery 函数上遇到问题。 无论我是否选中该框,此功能都只会用 0 更新表。
这是我的jquery函数:
$(function(){
$(document).on('click','.editEntry',function(e){
//process here you can get id using
var entryId = $(this).data('id');
var activeEntry = $(this).is(':checked') ? 1 : 0;
$("#id").val( entryId );
$("#active").val( activeEntry );
$('#update-entry').click( function (event) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": "includes/process-entry.php",
"data":{
"id" : $('#id').val(),
"active" : $('#active').val()
},
"success": function() {
$('#updated').show();
window.setTimeout(function(){location.reload()},400);
}
});
});
});
});
<input name="id" type="text" disabled="disabled" id="id" size="4" value ='1'>
<input type="checkbox" name="active" id="active">
谁能让我知道为什么在检查时没有将"1"插入数据库是不正确的?
提前谢谢你。 如果有更多信息,请告诉我
更改
"active" : $('#active').val()
自
"active" : activeEntry
复选框没有value
属性。
我已经
想出了如何让它正常工作:
不得不移动这一行:
var activeEntry = $(this).is(':checked') ? 1 : 0;
在 #update 输入功能内。 以下是更新的代码:
$(function(){
$(document).on('click','.editEntry',function(e){
//process here you can get id using
var entryId = $(this).data('id');
$("#id").val( entryId );
$("#active").val( activeEntry );
$('#update-entry').click( function (event) {
var activeEntry = $(this).is(':checked') ? 1 : 0;
$.ajax({
"dataType": 'json',
"type": "POST",
"url": "includes/process-entry.php",
"data":{
"id" : $('#id').val(),
"active" : $('#active').val()
},
"success": function() {
$('#updated').show();
window.setTimeout(function(){location.reload()},400);
}
});
});
});
});
<input name="id" type="text" disabled="disabled" id="id" size="4" value ='1'>
<input type="checkbox" name="active" id="active">
相关文章:
- 使用jquery将mysql数据获取到新的表行中
- 将地理编码结果转换为php变量以发布到mysql数据库
- 如何使用JS禁用表行,并在MYSQL中插入所选选项
- chrome.tabs.update() 重定向到 'chrome-extension://invalid/'
- 从MySQL数据库中获取输入数据需要两次页面刷新
- 将一个表的id与另一个表中的user_id进行匹配,以获取mysql中的记录
- 在php和mysql中选择选项.一旦选择了选项,就列出我的sql数据库数据
- 如何使用PHP将javascript变量添加到mysql数据库中
- 将phonegap图像发布到php/mysql-图像字段从发布请求中消失
- 在node.js-mysql中执行UPDATE查询不起作用
- 更新从Mysql查询检索到的数据?Node.js节点mysql
- 单击鼠标,用MySQL数据填充html表单输入字段
- 浓缩一系列mySQL查询
- jQuery to pass Checkbox Update mysql
- Javascript for while with mysql update when not having value
- MySQL UPDATE只更新整数,不更新字符串
- jQuery移动mySQL - UPDATE不工作
- Mysql UPDATE使用PHP和AJAX,不能更新数据库
- 为什么我的MYSQL UPDATE语句不会更新
- PHP/MySQL OnClick Update MySQL