首页 文章

codeigniter中jquery.ajax的内部服务器错误

提问于
浏览
0

这是我的ajax代码

$.ajax({
                method: 'post',
                url: "<?php echo base_url(); ?>"+"ci_ajax/test",
                data: {run : "1"},
                success: function(data) {
                    $("#index_all").html(data);

                },
                error: function(e) {
                    console.log('Error' + e);
                },
            });

这是我在控制器中的服务器端方法代码

public function test(){
    $post = $this->input->post("run");

    echo $post;
}

但在控制台日志中我收到此错误

POST http:// localhost / ci_ajax / test 500(内部服务器错误)

和console.log错误函数的结果是

错误[object object]

任何解决它的想法?

1 回答

  • 0

    从ajax代码更改 methodtype

    你的ajax应该是这样的:

    $.ajax({
          type: 'post',
          url: "<?php echo base_url('ci_ajax/test'); ?>",
          data: {run : "1"},
          success: function(data) {
             console.log(data);
             $("#index_all").html(data);
    
          },
          error: function(e) {
             console.log('Error' + e);
          },
    });
    

    你的 test 方法应该是这样的:

    public function test()
    {
        $post = $this->input->post("run");
    
        echo $post;
        exit;
    }
    

相关问题