codeigniter中没有给出Ajax调用

codeigniter中没有给出Ajax调用,ajax,codeigniter,Ajax,Codeigniter,Ajax调用不提供给控制器。我在一个页面上有多个表单。很抱歉,jquery尚未准备好 public function get_all_comments() { echo 'OK'; } $(函数(){ $(“#查看_注释”).submit(函数(e){ var id=$(“#post_id_for_view_comment”).val(); $.ajax({ url:“index.php/post_comment/get_all_comments”, 类型:“POST”

Ajax调用不提供给控制器。我在一个页面上有多个表单。

很抱歉,jquery尚未准备好

public function get_all_comments()
{   
    echo 'OK';  
}   
$(函数(){
$(“#查看_注释”).submit(函数(e){
var id=$(“#post_id_for_view_comment”).val();
$.ajax({
url:“index.php/post_comment/get_all_comments”,
类型:“POST”,
数据:{post_id_for_view_comment:id},
成功:功能(msg){
警报(msg);
}
});
e、 预防默认值();
});
});

这里有一种新的方法来实现您的需求:

    $(function(){
        $('#view_comment').submit(function(e) {
        var id = $("#post_id_for_view_comment").val();
        $.ajax({
             url: "<?php echo base_url()?>index.php/post_comment/get_all_comments",
             type: "POST",                          
             data: {post_id_for_view_comment:id} ,
             success: function(msg) {
                   alert(msg); 

             }
        });
             e.preventDefault();
        });
     });

真的希望我能帮上忙。

您是没有输入var秒分号还是输入错误?
var id=$(“#post_id_for_view_comment”).val()
///code>
数据:{post\u id\u for\u view\u comment:id}
和var sec定义的结尾@阿比基谢拉尔
public function get_all_comments()
{   
    echo 'OK';  
}   
    $(function(){
        $('#view_comment').submit(function(e) {
        var id = $("#post_id_for_view_comment").val();
        $.ajax({
             url: "<?php echo base_url()?>index.php/post_comment/get_all_comments",
             type: "POST",                          
             data: {post_id_for_view_comment:id} ,
             success: function(msg) {
                   alert(msg); 

             }
        });
             e.preventDefault();
        });
     });
$('#post_button').click(function(e){
e.preventDefault;
var sec = $('#post_id_for_view_comment').val();
//no need to mention index.php when using site_url() function
 $.post('<?php echo site_url("post_comment/get_all_comments")?>', 
{"post_id_for_view_comment": sec },
         function(data.res == "ok"){ // simple test if it returned ok
         //here you can process your returned data. 
         }, "json"); //**
});
function get_all_comments()
{
//getting your posted sec token.
   $sec = $this->input->post('post_id_for_view_comment'); 
   $data['res'] = "ok";// return anything you like.
// you should use json_encode here because your post's return specified as json. see **
   echo json_encode($data); //$data is checked in the callback function in jquery.
}