简体   繁体   English

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

[英]Internal server error for jquery.ajax in codeigniter

This is my ajax code 这是我的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);
                },
            });

and this is my server side method code in controller 这是我在控制器中的服务器端方法代码

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

    echo $post;
}

but in console log I receive this error 但是在控制台日志中,我收到此错误

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

and console.log result for error function is 和console.log错误功能的结果是

Error[object Object] 错误[对象对象]

any idea for resolve it? 有解决的主意吗?

Change method to type from the ajax code 更改method以从ajax代码type

Your ajax should be like this : 你的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);
      },
});

Your test method should be like this : 您的test方法应如下所示:

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

    echo $post;
    exit;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM