weixin_33736832 2019-05-03 08:34 采纳率: 0%
浏览 24

HTTP请求上的404

When I try to make an ajax request to a codeigniter route I get an 404 error

The root folder of the project is http://localhost/control_cuotas/

this is the controller(index works):

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Control_cuotas_controller extends CI_Controller {

    public function index()
    {
        $data = array();
        $tables = $this->getTables();
        $data['tables'] = $tables;
        $this->load->view('main/main_view', $data);      
    }

    public function getData($data){
        var_dump($data);
    }

    private function getTables(){

        $sql = "SELECT TABLE_NAME " 
            ."FROM INFORMATION_SCHEMA.TABLES "
            ."WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME LIKE 'datos_%'";
        $query = $this->db->query($sql);
        $tables = array();

        foreach ($query->result() as $row){
            $name = substr($row->TABLE_NAME,0,-2);
            if(!in_array($name,$tables)){
                array_push($tables, $name);
            }
        }

        return $tables;
    }

and this is the javascript:

$(document).ready(function(){

    $('#tables').change(function(){
        var selected = $(this).val();
        $.ajax({
            url:'getData/'+selected
        });
    });
});
}

an this is the route

$route['getData/(:any)']['GET'] = 'control_cuotas_controller/getData/$1';

The request is done on the following url

http://localhost/control_cuotas/getData/selected_value
  • 写回答

2条回答 默认 最新

  • weixin_33701617 2019-05-06 07:23
    关注

    Please Check .htaccess file

    and Try this code;

    RewriteEngine on
    RewriteCond $1 !^(index\.php|public|\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1
    

    OR

    $(document).ready(function(){
    
        $('#tables').change(function(){
            var selected = $(this).val();
            $.ajax({
                url:'http://localhost/control_cuotas/getData/'+selected
            });
        });
    });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作