<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 调用未提供给控制器。我在单页上有多个表格。