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
            });
        });
    });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 家用射频美容仪技术规格
  • ¥25 matlab数值溢出该怎么解决?
  • ¥15 大家帮我看看为什么错了
  • ¥15 unity互动琴弦抖动效果
  • ¥15 做了个的二极管反向饱和电流测量电路,但是测试达不到效果
  • ¥15 nginx无证书访问https失败
  • ¥15 树莓派启动AP热点传入数据
  • ¥15 multisim中关于74ls192n和DSWPK开关的问题(相关搜索:计数器)
  • ¥15 在误装Windows server2019 后如何利用Windows.old恢复?
  • ¥20 代码实现状态连接包过滤防火墙的设计与实现