【发布时间】:2015-09-20 12:02:58
【问题描述】:
我目前正在做一个 ajax 添加、更新和删除。我想我会从删除开始,因为它是最简单的,希望它可以在其他方面对我有所帮助。
在 jquery 中(这是在 $doc.ready 中并且事件被正确触发)
if ($a == "Delete")
{
var postid = $(this).next('.postid').val();
$(this).closest(".todo-content").fadeOut();
jQuery.ajax({
type: "POST",
dataType: 'json',
url: "<?=base_url()?>.index.php/classes/deletepost",
data: {postid: postid},
async: false,
});
}
在html中
<form method="post">
<button class="btn" onclick="return confirm('Are you sure to delete this item?')">Delete</button>
<input type="hidden" value="<?php echo $id; ?>" name="postid">
</form>
在控制器中
public function deletepost(){
$id = $this->input->post('postid');
$data = array('active' => 0);
$this->Model_name->deletepost($id,$data);
redirect('/abc/123');
}
这已经在工作了,但是我打算将 crud 制作成 ajax。我正在尝试将 postid 从 ajax 传递到控制器以删除此帖子。 fadeout 已经有效,但只有 ajax 无效。我对 ajax 很陌生,所以我不知道我哪里出错了,我可能还会再次询问有关 crud 其他部分的问题。
【问题讨论】:
标签: javascript php jquery codeigniter