【问题标题】:Internal server error for jquery.ajax in codeignitercodeigniter 中 jquery.ajax 的内部服务器错误
【发布时间】:2018-06-24 12:07:20
【问题描述】:

这是我的 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结果是

错误[对象对象]

有解决办法吗?

【问题讨论】:

  • .htaccess 文件的位置是什么
  • @pradeep 在 codeigniter 中有两个默认的 .htaccess。一个在根目录,一个在应用程序文件夹

标签: javascript jquery ajax codeigniter codeigniter-3


【解决方案1】:

将 ajax 代码中的 method 更改为 type

你的 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;
}

【讨论】:

  • 还显示您的控制器ci_ajax 类,并确保.htaccess 文件应位于应用程序文件夹之外的基本文件夹中
  • 从应用程序文件夹中删除.htaccess文件并重试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多