我不太擅长 ajax 和 jQuery 的东西。在此我想用复选框值更新我的数据库表。这里来自ctp文件的代码
$(".chk").click(function(e){
e.preventDefault();
var id = $(this).parent().attr('id');
$.ajax({
type: 'post',
url:'/Home/chktodo',
data: 'id='+id,
success : function(data) {
}
})
});
foreach($View as $view):
echo $view['Todolist']['details'];?> :To Do List
<div id = "<?= $view['Todolist']['id']?>">
<a id="todo" href="#">add to do</a>
<div id="clearNiPela-<?= $view['Todolist']['id'] ?>"></div>
</div>
<?php $todo = $view['Todo']; foreach($todo as $do): ?>
<div id="hours"> Hours :<?= $do['hours'];?></div>
<div id="description"> Description :<?= $do['description'];?></div>
<?=
$this->Form->create('Todo',array('url' => '/Home/chktodo'));?>
<div id="<?='desc'.$do['id']?>">
<?=$this->Form->input('active',array('class' => 'chk','type' => 'checkbox','div'=>false))
.'<br />'.
$this->Form->end(); ?>
</div>
<?php endforeach; endforeach; ?>
这里是我的控制器的代码
public function chktodo() {
if($this->request->is('ajax')) {
$this->loadModel('Todo');
$this->request->data['Todo']['id'] = $this->request->query('id');
if($this->Todo->save($this->request->data)) {
$this->Session->setFlash('Done','flash',array('alert' => 'info'));
$this->redirect('/');
}
}
}
现在我有 3 个复选框作为数据库值。
问题 1 我无法更改数据库中的数据。我的意思是它不是用复选框的值更新数据库