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 halcon联合c#遇到了问题不能解决
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集