【发布时间】:2012-12-20 04:54:21
【问题描述】:
<script type="text/javascript" language='javascript'>
$('#view_comment').submit(function() {
alert("msg");
var sec={'post_id_for_view_comment' : $("#post_id_for_view_comment").val()}
$.ajax({
url: "<?php echo base_url().'index.php/'; ?>post_comment/get_all_comments",
type: 'POST',
data: sec,
success: function(msg) {
alert(msg);
}
});
});
</script>
表格
<form id="view_comment" method="post" >
<input type="hidden" name="post_id_for_view_comment" id="post_id_for_view_comment" value="<?php echo $row->post_id; ?>" />
<input type="submit" id="post_button" value="View Comments" />
</form>
控制器
public function get_all_comments()
{
echo 'OK';
}
Ajax 调用未提供给控制器。我在一个页面上有多个表单。
【问题讨论】:
-
您是错过了 var sec 分号还是只是输入错误?
-
var id = $("#post_id_for_view_comment").val();/////////////data: {post_id_for_view_comment : id} -
和 var sec 定义的结尾?? @AbhijitShelar
标签: ajax codeigniter